數字與字符串互轉及拼接方法


death_age = 80


name = input("your name:")
age = input("your age:") #input
#接收的所有數據都是字符串,即便你輸入的是數字,但依然會被當成字符串來處理

print( type(age))
#int integer =整數 把字符串轉成int,用int(被轉成的數據)
#srt string = 字符串 把數據轉成字符串用str(被轉成的數據)
print("Your name:",name)
# str 強制轉成字符串
#print("Your can still live fur ",str(death_age - int(age)),"years ...... ") =三個獨立的字符串
#print("Your can still live fur " + str(death_age - int(age)) +"years ...... ") =拼接成一個字符串
print("Your can still live fur ",death_age - int(age),"years ...... ")


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM