print('----1차시 시퀀스 자료형-----')
#시퀀스 자료형: 순서가 있는 자료형 - 문자열,리스트
'''
시퀀스 자료형 특징
1. 원소에 순서가 있다 - 인덱싱, 슬라이싱
2. 특정 원소를 조회할 수 있다 - in
#기본형: 조회할 원소 in 시퀀스
3. 길이를 확인할 수 있다 - len(시퀀스)
4. 연결 연산을 할 수 있다 +
5. 반복 연산을 할 수 있다 *
'''
print('hi' * 3)
c = ['bye'] * 5
print(c)
print('----2차시 반복문 for----')
#기본형: for 변수 in 시퀀스:
# <반복할 명령>
#시퀀스의 길이만큼 반복된다
for i in [1, 2, 3]:
print(i)
print('----3차시 리스트 점 표기법----')
#점 표기법 : 점.을 이용해서 리스트나 문자열에 연결된 함수를 사용하는 것
#append() 리스트 맨 뒤에 추가
#리스트.append(추가할 원소)
a = [1, 2, 3]
a.append(4)
print(a)
#insert() 원하는 곳에 추가
#리스트.insert(추가할 위치, 추가할 원소)
b = [1, 2, 4, 5]
b.insert(2, 'a')
print(b)
#remove() 원하는 값을 삭제
#리스트.remove(삭제할 원소)
c = [3, 1, 2, 3, 4]
c.remove(3)
print(c)
#sort() 순서대로 정리: 가나다,abc,123
#리스트.sort()
d = [7, 2, 4 ,6, 1, 3, 2, 9, 5]
d.sort()
print(d)
print('----4차시 반복문 range----')
sum = 0
for i in [3, 6, 9]:
sum = sum + i
print(sum)
#range(a, b) : a부터 b미만까지의 자연수 시퀀스
#a:시작 , b:종료(미만)
for i in range(5,10):
print(i)
for i in range(5):
print(i)
count = 0
for i in range(1, 11):
count = count + i
print(count)
print('----5차시 반복문 while----')
#while문 : 조건이 참True인 동안 명령을 계속 반복
'''
기본형
while 조건:
반복할 명령
'''
i = 3
while i > 0:
print(i)
i = i - 1
print('땡!')
print('----6차시 반복문 break----')
while True:
print('계속 반복 중!')
break
#break : 반복문을 강제로 멈추게 하는 명령어
i = 0
while True:
print('!')
if i == 3:
break
i = i + 1
print(i)
#while : 몇 번 반복할지 모를 때
#for : 몇 번 반복할지 미리 알고 있을 때
To embed this project on your website, copy the following code and paste it into your website's HTML: