使用者互動input

2022-09-15 12:09:06 字數 595 閱讀 3284

input() 函式

接收到的都是str,如果輸入為數字,列印結果想進行運算,此時需要轉義.

語法:內容=input("提示資訊")

這裡可以直接獲取到使用者輸入的內容.

a = input("請輸入你的名字:")

print (type (a) ) #列印一下 a 的型別, 顯示 class 'str'

print ("my name is "+a) 或者寫成 print ("my name is ",a) 是一樣的結果

假如使用者輸入的為數字,以上執行時數字不會進行計算,只是進行連線,,此時需要轉義

例如a = input("請輸入乙個數字:")

b = input ("請在輸入乙個數字:")

c = int(a)

d = int(b)

print (c + d)

也可以寫成

a = int ( input ("請輸入乙個數字:"))

b = int ( input ("請再輸入乙個數字:"))

print ( type(a),type(b) )

print ( a + b )

使用者互動input

input基本用法 name input 請輸入你的名字 age input 請輸入你的名字 print name,age 1 等待輸入 2 將你輸入的值賦值給了前面的變數 3 input出來的資料型別全是字串型別 例題 使用者登陸 三次機會重試 input 心中有賬號,密碼,用while迴圈 i ...

python 使用者互動輸入input的4種用法詳解

使用者輸入 1 使用input來等待使用者輸入。如 username input username password input password print username,password 2 格式化輸出 第一種方法 字串拼接 不建議使用,太耗記憶體 name input name age i...

Python基礎 input互動功能

variable input 表示執行後,可以在螢幕中輸入乙個數字,該數字會賦值給自變數。看 get input input please input a number print this is a get input 輸出please input a number 100this is a 10...