a = "Hello "
b = "World"
c = a + b
print(c)
a = "Hello "
b = a * 3
print(b)
a = "Hello World!"
a.replace("World", "Heezeo")
print(a)
## replace 함수를 쓰면, 새로운 공간에 합쳐진 문자열을 만들어넣기 때문
a = a.replace("World", "Heezeo")
print(a)
a = "Apple, Banana, Cake, Donut"
b = a.split(",")
print(a)
print(b)
#print(b) 결과의 공백은 어떻게 할까?
a = " Banana"
print(a)
# 문자열 양쪽의 공백 지우기
a = a.strip()
print(a)
# 문자열 왼쪽 공백 지우기
a = " Banana "
a.lstrip()
# 문자열 오른쪽 공백 지우기
a = " Banana "
a.rstrip()
#split()으로 리스트로 나눠진 모든 문자열에서 한 번에 공백을 지우려면?
a = "Apple, Banana, Cake, Donut"
b = a.split(",")
print(b)
b.strip()
[c.strip() for c in b]
c = [c.strip() for c in b]
c
a = "apple"
a.upper()
a = "APPLE"
a.lower()
name = "Heezeo"
print("Hello", name)
# old
print("%s and %d" % ("Apple", 10))
# new
print("{} and {}".format("Apple", 10))
print("{}".format(4/3))
print("{:.2f}".format(4/3)) #Float 2자리수까지
print("{:04d}".format(12)) #Decimal 4자리
(0 * 9/5) + 32 # 인풋이 될 부분 = 0 / 아웃풋이 될 부분 = 전체
def convert_temp(c):
return (c * 9/5) + 32
convert_temp(30) #결과 값은 계산해서 리턴했지만 출력해주지 않기 때문에 표기되지 않는다
print("-"*50)
print(convert_temp(30)) #출력(print)해주었기 때문에 실행시키면 결과값을 볼 수 있다.
def add(a, b):
return a + b
add(3,4)
def mul(a, b):
return a * b
mul(3,4)
def add_and_mul(a, b):
return add(a, b), mul(a, b)
add_and_mul(3, 4)
# 두 수를 더한 값과 곱한 값을 같이 리턴하는 함수
def add_and_mul(a, b = 0):
return add(a,b), mul(a,b)
print(add_and_mul(3))
print(add_and_mul(3,3))
a = [1, 2, 3]
a.append(4)
print(a)
a = [1, 2, 3]
a.insert(1, 0) #1을 인덱스 0자리에 넣어라
print(a)
a = [1, 4, 2, 6, 5, 3]
a.sort()
print(f"오름차순 정렬: {a}")
print("-"*30) #점선 구분
a.sort(reverse = True)
print(f"내림차순 정렬: {a}")
a = []
a.append(1)
a.append(2)
a.append(3)
print(a)
a.pop()
print(a)
a.pop()
print(a)
a.pop()
print(a)
from collections import deque
queue = deque([1, 2, 3])
print(queue)
print("-"*30) #구분선
queue = deque([])
queue.append(1)
print(queue)
queue.append(2)
print(queue)
queue.append(3)
print(queue)
queue.popleft()
print(queue)
queue.popleft()
print(queue)
queue.popleft()
print(queue)
tu = (1, 2, 3)
print(tu)
tu = (1, 2, 3)
print(tu)
tu[0] = 5
tel = {'a':1, 'b':2, 'c':3}
print(tel)
tel = dict(a=1, b=2, c=3)
print(tel)
tel = {'heezeo': '01033334444', 'heezeo': '01022224444'}
print(tel['heezeo'])
print(tel)
tel = {'heezeo': '01033334444', 'heezeo': '01022224444'}
print(tel.keys())
tel = {'heezeo': '1234', 'heezy': '1111', 'kimzeo': '3333'}
print(tel.keys())
print("-"*30) #구분선
keys = tel.keys()
for key in keys:
print(key)
print(keys)
keys = list(keys) #리스트 형태로 형변환
print(keys)
tel = {'heezeo': '3434', 'kimzeo': '4545', 'heezy': '5678'}
print('heezeo' in tel)
print('heezybusy' in tel)
print(tel.get('heezeo'))
print(tel.get('kimzeo'))
print(tel.get('heezeo', 'N/A'))
print(tel.get('heezybusy', 'N/A'))
a = {1, 2, 3}
print(a)
type(a)
a = {1, 2, 1, 3}
print(a)
print(a[0])
# 셋(set) feat. 형변환(Casting)을 사용해 중복 제거!
a = [1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]
a = set(a)
print(a)
a = list(a)
print(a)
a = {1, 2, 3}
b = {2, 3, 5}
# 교집합
print(a & b)
#합집합
print(a | b)
#차집합
print(a - b)
print(b - a)