Python 프로그래밍/기초 문법

[모두를 위한 파이썬] 예약어,순차문,조건문 및 반복문

SW Developer 2024. 3. 18. 13:50

예약어,순차문,조건문 및 반복문

: 언어로써 파이썬

<<

 

 

[파이썬의 요소]

- Vocabulary / Words

- Sentence structure

- Story structure

 

 

① 예약어 (Reserved Words)

예약어를 변수의 이름 혹은 식별자로는 사용할 수 없다

#<Reserved Words>
"""
False
None
True
and
as
assert
break
class
if
def
del
elif
else
except
return
for
from
global
try
import
in
is
lambda
while
not
or
pass
raise
finally
continue
nonlocal
with
yield
"""

 

② 문장 혹은 줄 (Sentences or Lines)

문장 단위 혹은 줄 단위로 코드를 입력한다.

 

③ 순차문

레시피나 설명글과 같은 진행순서가 있다

 

※ 코드예시

x = 2
print(x) #2
x = x + 2
print(x) #4

 

 

④ 조건문

특정 조건에 따라 원하는 값을 출력하거나 출력하지 않는다.

 

※ 코드예시

x = 5
if x < 10:
	print('Smaller') #Smaller
if x > 20:
	print('Bigger')
print('Finis') #Finis

 

 

⑤ 반복문

지정한 변수의 변화 규칙에 따라 반복문을 실행한다

※ 코드예시

n = 5
while n > 0 :
	print(n)
    n = n - 1
print('Blastoff!')

 

출력결과

 

 

 

 

 

※ 해당 게시글은 개인 학습의 목적으로, 아래 강의를 수강한 후 정리한 학습노트입니다.

http://www.boostcourse.org/cs122