int(ข้อมูล) แปลงข้อมูลให้เป็น integer
float(ข้อมูล) แปลงข้อมูลให้เป็น float
str(ข้อมูล) แปลงข้อมูลให้เป็น string
list(ข้อมูล) แปลงข้อมูลให้เป็น list
tuple(ข้อมูล) แปลงข้อมูลให้เป็น tuple ยกตัวอย่างดังโค้ดนี้
int_=100
float_=5.94
str_="NeoIsTheBest"
str_1=str(int_)
str_2=str(float_)
print(int(float_),type(int(float_)))
print(float(int_),type(float(int_)))
print(str_1+str_2,type(str_1))
print(list(str_2),type(list(str_2)))
print(tuple(str_),type(tuple(str_)))
จะได้ผลลัพธ์ดังนี้ (ขออนุญาตไม่อธิบายนะ ลองวิเคราะห์กันดู)
int_=100
float_=5.94
str_="NeoIsTheBest"
str_1=str(int_)
str_2=str(float_)
print(int(float_),type(int(float_)))
print(float(int_),type(float(int_)))
print(str_1+str_2,type(str_1))
print(list(str_2),type(list(str_2)))
print(tuple(str_),type(tuple(str_)))
แหล่งที่มาแอบอ้าง http://www.pitt.edu/~naraehan/python2/data_types_conversion.html