본문 바로가기

전체 글

- 문법 - 반복문 반복문 : 프로그램이 순차적으로 실행되다가 어떤 조건 하에서 일련의 코드들을 반복적으로 실행되도록 하는 것 list에 있는 data를 하나씩 가져오는 것 The for statement is used to iterate over the elements of a sequence (such as a string, tuple or list) or other iterable object: for_stmt ::= "for" target_list "in" expression_list ":" suite ["else" ":" suite] n번 반복하도록 하는 것 for i in range(10): print(i) i = 5 # this will not affect the for-loop # because i will .. 더보기
- 문법 - List Tutorial - 어떻게 결합하면 되는지 알려주는 Recipe Library Reference - 파이썬 기능에 대한 정보 Language Reference - 파이썬 문법 Tutorial - Lists 집에 살림이 적을 땐 가구가 별로 필요 없음. 살림이 많아지면 물건을 꺼내는데 어려움이 생김. 수납상자가 필요함. 어떤 가구를 쓸 것인지에 대한 고민. 데이터가 적으면 변수로 정리하는 것이 가능하지만 많아지면 불가능. 정교하게 정리정돈할 때 필요한 게 List 대괄호로 시작하면 list 대괄호 안에 있는 것은 index라고 표현. 첫번째 자리는 index 값이 0. 프로그래머들은 숫자를 0부터 센다. s=[1,'four',9,16,25] print(s) print(s[1]) list에 몇 개의 값이 있.. 더보기
- 문법 Boolean #Number 숫자 (#integer) - 무한함 #String 문자 - 유한하지만 매우 많음 #Boolean true 와 false 두가지로 이뤄짐. #Boolean print(True) print(False) #Comparison operator print(1==1) #True print(1 더보기
- 문법, 데이터타입, 숫자 어떠한 값을 만들어 내는 간단한 코드를 표현식(expression)이라고 함. - 값은 숫자, 수식, 문자열 등과 같은 것 표현식이 하나 이상 모이면 문장(statement), 파이썬은 한 줄이 하나의 문장. 문장이 모여서 프로그램(program) 문자열의 표현 문자열 시작과 끝은 ' ' 또는 " " 기본적으로 작은 따옴표 많이 씀. 문자열 안에 작은 따옴표를 표현하고 싶을 때 큰따옴표를 사용. 큰따옴표도 사용하고 싶을 때, 큰따옴표 앞에 \를 붙이면 직후의 문자 하나를 기본 문자로 사용. (#escape) #escape print("hell'o' \"w\"orld") 새로운 줄을 사용하고 싶을 때. \n #newline print('H\ne\nl\nl\no') 글 바꾸는 다른 방법. 문자열 맨 앞뒤 따.. 더보기
#Conditional #if #elif user_id = input('id?') user_pwd = input('password?') ''' if user_pwd == '111111': print('Hello master') else: print('who are you?') ''' ''' if user_id == 'prosumen': if user_pwd == '111111': print('Hello master') else: print('Who are you?') else: print('Who are you?') ''' if user_id == 'prosumen' and user_pwd == '111111': print('Hello master') elif user_id == 'inseon' and user_pwd == '1234': pri.. 더보기
#number #string #Boolean #Expression #ComparisonOperator #MembershipOperator #Number print(1) #string print('Hello world') #Boolean print(True) print(False) #Expression print(1+1) print('Hello '+'world') #Comparison operator print(1==1) print(1 더보기
#positional formating #Named placeholder #positional formating print("Russia's invasion of Ukraine puts tech giants in an untenable situation. {}({}), the CEO of high-end electric vehicle manufacturer Tesla , and incidentally the richest man in the world, finds himself in a delicate position. by {}.".format('Yoo',35,'Yoo')) #Named placeholder print("Russia's invasion of Ukraine puts tech giants in an untenable situation. {name}({age:d}.. 더보기
#length #index #repeat a='hello pyhthon' print(a) #length print(len(a)) #index print(a[0]) print(a[2:5]) #repeat print((a+'\n')*2) 더보기