#1차시 점 표기법
#점 표기법 리스트.함수
#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 = [1, 2, 3, 4, 2]
c.remove(2)
print(c)
#sort() 순서대로 정리
#리스트.sort()
d = [8, 7, 2, 1, 6, 5, 4, 3]
d.sort()
print(d)
#2차시 시퀀스
#시퀀스 자료형: 순서가 있는 자료형 - 문자열, 리스트
#1. 원소에 순서가 있다 - 인덱싱, 슬라이싱
text1 = 'twice'
print(text1[2])
print(text1[1:])
#2. 특정 원소를 조회할 수 있다 - in
#기본형: 조회할 원소 in 시퀀스
우리반 = ['백지안', '전의준']
print('박주현' in 우리반)
print('im' in 'time')
#3. 원소의 길이를 확인할 수 있다 - len()
#원소의 길이를 알려주는 함수: len(시퀀스)
print(len(우리반))
a = 'jewhszdgj zcbdsgvfiuahdhgbcfdsjf'
print(len(a))
#4. 연결 연산을 할 수 있다 +
print('안녕' + '하세요')
b = ['o', 'n'] + ['c', 'e']
print(b)
#5. 반복 연산을 할 수 있다 *
print('hi' * 3)
c = ['bye'] * 5
print(c)
#3차시 반복문 for
'''
for문 기본형 - 시퀀스의 길이만큼 반복된다
for 변수 in 시퀀스:
반복할 명령
'''
for i in 'abcd':
print(i)
sum = 0
for i in [3, 6, 9]:
sum = sum + i
print(sum)
#4차시 range()
#range(a,b) : a부터 b미만까지의 자연수를 가진 시퀀스
#숫자가 중요
for i in range(5,10):
print(i)
#숫자보다 횟수가 중요
for i in range(5):
print(i)
total = 0
for i in range(1,11):
total = total + i
print(total)
#5차시 반복문 while
#while문 : 조건이 참True인 동안 명령을 계속 반복
'''
while 조건:
반복할 명령
'''
i = 3
while i > 0:
print(i)
i = i - 1
print('땡!')
#6차시 반복문 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: