print("Hello")
python3에서 문자열은 크게 4가지 방법으로 표현할 수 있습니다.
큰 따옴표 " 이용
작은 따옴표 ' 이용
큰 따옴표 3개를 연속으로 """ 이용
작은 따옴표 3개를 연속으로 ''' 이용
3번과 4번처럼 3개를 연속으로 사용하는 경우, 다음과 같이 문장을 표현할 수 있습니다.
'''
Hello World
Python is fun
'''
\를 붙여주면 이를 문자로 인식,를 사이에 두고print(3, 5) -> 3 5
print(3, 5, sep=":") -> 3:5
print(3, 5, sep=" ") -> 3 5
a = 5
print(a)
a = "toy"
b = 3.5346
print(type(a)) # <class 'str'>
print(type(b)) # <class 'float'>
a, b = 5, 3
c = a + b
print("c =", c)
a = 5
print("A is %d" % a)
b = "apple"
print("B is %s" % b)
print("A is %d and B is %s" % (a, b))
문자열의 경우 %s를, 문자의 경우 %c를, 정수의 경우 %d, 실수의 경우 %f
print("A is {0} and B is {1}".format(a, b))
print("A is {new_a} and B is {new_b}".format(new_a=a, new_b=b))
print("B is {1} and A is {0}".format(a, b))
print("B is {new_b} and A is {new_a}".format(new_a=a, new_b=b))
a, b = 5, "apple"
print(f"A is {a}")
print(f"B is {b}")
print(f"A is {a} and B is {b}")
a = 33.567268
print("%.4f" % a) #소수점 4번째자리까지 출력
a = 33.567268
print("{0:.4f}".format(a))
print(f"{a:.4f}")
a, b = 5, 3
temp = a
a = b
b = temp
print(f"A is {a} B is {b}")
a, b = 5, 3
a, b = b, a
print(f"A is {a} B is {b}")
a, b, c = 5, 3, 9
a = b = c #오른쪽부터 진행 / c값이 b에 > b 값이 c에 => a,b,c 값이 c로 통일
print(f"A is {a} B is {b} C is {c}")