Python

이은룡·2022년 5월 2일
0

Python

목록 보기
1/1

data 타입

문자타입
import math
print('math.sqrt(4)', math.sqrt(4))
print('math.pow(4,2)', math.pow(4,2))
 
import random
print('random.random()',random.random())

리스트타입
students = ["egoing", "sori", "maru"]
grades = [2,1,4]
print("students[1]", students[1])
print("len(students)", len(students))
print("min(grades)", min(grades))
print("max(grades)", max(grades))
print("sum(grades)", sum(grades))
 
import statistics
print("statistics.mean(grades)", statistics.mean(grades)) //평균
 
import random
print("random.choice(students)", random.choice(students))

변수

name = 'egoing'
message = 'hi, '+name+' .... bye, '+name+'.'
print(message)

디버그:디버거를 이용함

입력과 출력

name = input('name: ')
message = 'hi, '+name+' .... bye, '+name+'.'
print(message)

pypi

//pip install pandas
import pandas
house = pandas.read_csv('house.csv')
print(house)
print(house.head(2))
print(house.describe())

bolean type

print(True)
print(False)

비교연산자

print('1 == 1', 1 == 1)
print('1 == 2', 2 == 1)
print('1 < 2', 1 < 2)
print('1 > 2', 1 > 2)
print('1 >= 1', 1 >= 1)
print('2 >= 1', 2 >= 1)
print('1 != 1', 1 != 1)	//!:반대의 의미
print('2 != 1', 2 != 1)

조건문
if문

input_id = input('id : ')
id = 'eunryong'
if input_id == id:
    print('Welcome')

if else문

input_id = input('id : ')
id = 'eunryong'
if input_id == id:
    print('Welcome')
else:
    print('Who?')

elif문

input_id = input('id : ')
id1 = 'eunryong'
id2 = 'Lee'
if input_id == id1:
    print('Welcome')
elif input_id == id2:
    print('Welcome')
else:
    print('Who?')

조건문 중첩

input_id = input('id:')
id = 'eunryong'
input_password = input('password:')
password = '111111'
if input_id == id:
    if input_password == password:
        print('Welcome')
    else:
        print('Wrong password')
else:
    print('Wrong id')

반복문

names = ['eunryong', 'Lee']
for name in names:
    print('Hello, '+name+' . Bye, '+name+'.')
persons = [
    ['eunryong', 'Jinju', 'FrontEnd'],
    ['Lee', 'Seoul', 'BackEnd'],
]
print(persons[0][0])
 
for person in persons:
    print(person[0]+','+person[1]+','+person[2])
 
person = ['eunryong', 'Jinju', 'FrontEnd']
name = person[0]
address = person[1]
interest = person[2]
print(name, address, interest)
 
name, address, interest = ['eunryong', 'Jinju', 'FrontEnd']
print(name, address, interest)
 
for name, address, interest in persons:
    print(name+','+address+','+interest)

사전형

person = {'name':'eunryong', 'address':'Jinju', 'interest':'FrontEnd'}
print(person['name'])
 
for key in person:
    print(key, person[key])

persons = [
    {'name':'eunryong', 'address':'Seoul', 'interest':'FrontEnd'},
    {'name':'Lee', 'address':'Seoul', 'interest':'BackEnd'},
]
for person in persons:
    for key in person:
        print(key, ':', person[key])
        print('-----------------')

0개의 댓글