5.如何從用戶獲取輸入數據函數
# input函數 name = input("請輸入姓名:") age = input("請輸入年齡:") print(f'{age}歲的{name},你好!歡迎您!')
run結果:spa
6.字符串code
# 字符串 String # slash / 斜槓 backslash \ 反斜槓 # 轉義字符串 mystr1 = '"Song" Ke' mystr2 = "\"Song\" \n Ke" mystr3 = "songKe " print(mystr1 + ":字符串拼接") print(mystr2) print(mystr3 * 3) print("Ke" in mystr2)
run結果:blog
7.字符串格式化字符串
# 之前有我的叫鬆柯,他年齡是21歲了。 name = "鬆柯" age = 21 massage = "之前有我的叫" + name + ",他年齡是" + str(age) + "歲了。" msg = f"之前有我的叫{name},他年齡是{age}歲了。" print(massage) print(msg)
run結果:input