코멘토 청년취업사관학교 전Z전능 데이터 분석가 DAY16

·2025년 1월 14일

파이썬 기초 이해

#1 리스트

#리스트 method

colors = ['red', 'blue', 'white', 'black', 'purple']

colors.pop(1)             #값 반환
colors.remove('black')	  #값 삭제

colors

>['red', 'white', 'purple']


#2 조건문 if

bag = ['핸드폰', '책']
if '돈' in bag:
  print("택시타기")
else:
  print("걸어가기")
  
>걸어가기


#3 반복문 for/while

#while
i = 1
while i <= 30:
	print(i)
    i += 1
    
> 1
  2
  ..
  30

#for
for i in range(1, 31):       #1부터 30
	print(i)
for i in range(30):         #0부터 29
	print(i+1)              #1씩 더해서
    
> 1
  2
  ..
  30    



#반복문 활용

#코드 간결화
...
for i in range(5):
	numbers.append(int(input()))

#무한 루프
while True:      #조건식이 항상 참이므로 변화식 필요 X

..

	break        #반복문 빠져나옴


0개의 댓글