정수와 실수를 같이 연산하여 데이터 타입을 바꾼다 ex) 5 + 5.6 = 10.6
print(10/3) # 3.3333333333333335
print(10//3) # 3
print(10//3.0) # 3.0
바꾸고 싶은 데이터 타입으로 묶어준다
타입 | 의미 |
---|---|
bool() | bool로 변환 |
int() | int로 변환 |
str() | str로 변환 |
float() | float로 변환 |
char(정수) | 정수를 문자로 |
ord(문자) | 문자를 정수로 |
x, y, z = '100', 10.5, 20
print(int(x) + y) # 110.5
print(x + str(z)) # 10020
print(str(y) + str(float(z))) # 10.520.0
print(str((int(x)) + y) + str(z)) # 110.520
print(float(10)//3) # 3.0
pw = "a1b2c3"
en_pw = ""
de_pw = ""
for i in pw :
en_pw += chr(ord(i) * 9)
print("기존 비밀번호 : %s" %pw)
print("암호화된 비밀번호 : {pw}".format(pw=en_pw))
형변환이 참 간단하다.