運用input函數搜集信息 input()函數結果的賦值name = input('請輸入你的名字:') #將input()函數的執行結果(收集的信息)賦值給變數name input()函數的使用場景1.函數結果賦值 name=input()2.搜集信息 name=input(xxx)3.輸出結果 ...
運用input函數搜集信息
input()函數結果的賦值
name = input('請輸入你的名字:') #將input()函數的執行結果(收集的信息)賦值給變數name
input()函數的使用場景
1.函數結果賦值 name=input()
2.搜集信息 name=input(xxx)
3.輸出結果 print(name)
——————————————————————————————————
input()函數的數據類型
input()函數的輸入值(搜集到的回答),永遠會被【強制性】地轉換為【字元串】類型
choice = input('請輸入1或2:')
print(type(choice))
<class 'str'>
—————————————————————————————————————
input()函數結果的強制轉換
choice = int(input('請輸入您的選擇:'))
#將輸入值強制轉換為整數,並賦值給變數choice