본문 바로가기

파이썬 3장 정리- 맛보기(피보나치 수열, while(), print())


* 피보나치 수열


>>> # Fibonacci series:
... # the sum of two elements defines the next
... a, b = 0, 1
>>> while a < 10:
...     print(a)
...     a, b = b, a+b
...
0
1
1
2
3
5
8


- 다중 대입 複数同時の代入 (multiple assignment)


- while 문


while 조건:

body

- 조건 : true (1, 0이외) / false(0) / (조건 연산자 : <,>,==,<=,>=,!=)

- body : 들여쓰기 (tab, space) - 파이썬에서 문장을 덩어리로 묶는 방법


- print( )


>>> i = 256*256
>>> print('The value of i is', i)
The value of i is 65536

- 문자열의 따옴표 생략

- 인자 사이 자동 띄움 / 줄 바꿈 (개행문자)


>>> a, b = 0, 1
>>> while a < 1000:
...     print(a, end=',')
...     a, b = b, a+b
...
0,1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987,

- 키워드 인자 'end'

- 개행문자 제거

- 다른 문자로 끝나게 할 수 있음.