
값을 저장하는 메모리 공간
파이썬에서는 변수를 미리 선언하지 않는다.
변수에 저장해서 사용하는 값의 자료형으로 변수의 자료형이 결정
a = 12b = 12.04c = 3+4ja**b a%b a//b
## 원하는 위치의 문자를 선택할 수 있다. index는 0부터 시작
tx = "Hello!"
# 인덱싱
tx[-1]
# 슬라이싱
tx[:2]
# 문자 개수 계산
tx.count('e')
# 문자 찾기
tx.find('e')
tx.index('e')
# 문자 삽입
tx.join('Python')
# 대문자 변환
tx.upper()
# 소문자 변환
tx.lower()
# 공백제거
t = " Python is difficult. "
t.lstrip()
t.rstrip()
t.strip()
# 문자열 수정
t[2] = "i"
# 문자열 변경
t = "Python is difficult."
t.replac("difficult", "easy")
# 문자열 나누기
ts = "a, b, c, d"
t.split()
ts.split(",")
# 문자열 길이
len(t)
dic = {'name' : 'Hong', 'phone' : '01012345678', 'birth' : '1225'}
## 순서를 가지고 있지 않아 인덱스 사용 불가
# dic[-1]
dic['name']
# 원소 추가
dic['email']="@gmail.com"
# 원소 삭제
del dic['email']
# key의 value 구하기
dic['phone']
# value 변경
dic['name'] = 'lim'
# key값
dic.keys()
# value값
dic.values()
# key, value 쌍
dic.items()
# 딕셔러리 길이 계산
len(dic)
# 원소 전체 삭제
dic.clear()
if <조건식>:
명령문1
명령문2
if <조건식1>:
명령문1
elif <조건식2>:
명령문2
else:
명령문3
명령문4
==, !=, <, >, <=, >=and, or, notx in list, x in tuple, x in stringpassis, isinstance()level = ['A', 'B', 'C', 'D', 'F']
pass_level =level[:3]
mine = "D"
if mine in pass_level:
print("Pass")
elif mine == level[-1]:
print("Fail")
else:
print("Retake")
for <반복변수> in <반복범위>:
명령문
range(start, stop, step)
for (first, second) in <반복범위>:
명령문
for (first, _) in <반복범위>:
명령문
for <반복변수 1> in <반복범위>:
for <반복변수2> in <반복범위>:
명령문
[명령문 for <반복변수> in <반복범위> if <조건식>]{명령문 for <반복변수> in <반복범위>}{key_expression: value_expression for item in <반복범위> if <조건식>}for i in range(1,11):
if i%2 ==0:
print(i)
for i in range(10):
if (i+1)%2 ==0:
print(i+1)
for i in range(2,10):
print(f"{i}단")
for j in range(2,10):
print(f"{i}*{j}={i*j}")
while <조건식>:
명령문
# break : 반복문에서 빠져나옴
b=0
while True:
b = b + 1
print(b)
if (b>3):
break
# print(b)
# continue : 처음으로 돌아가서 다음 반복을 실행
b=0
while b <= 5:
b = b + 1
if b==2:
print("continue test")
continue
print("Add continue:",b)
result = 1
for i in range(1,101):
result *= i
print(result)
# math 라이브러리 이용한 코드
import math
math.factorial(100)
i =0
flag = True
while flag:
i = i+1
if i**2 > 30:
flag = False
print(i**2)
*
**
***
****
*****
******
*******
********
*********
**********
a = 0
while True:
a = a +1
# a +=1
print("*"*a)
if a==10:
break