Python【input()函數】


運用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

 

 


免責聲明!

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



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