python實現鍵盤輸入多個值

2021-10-02 14:38:07 字數 578 閱讀 2999

python 2裡面讀取輸入的函式是raw_input(), python 3的是input(),讀入乙個值後回車讀取輸入就退出了,想要一次讀取多個輸入,可以像下面這樣:

a, b = raw_input().split()

1 2a

out[224]: '1'

bout[225]: '2'

上面儲存的是字串,可以用map轉化為int型的

a, b = map(int, raw_input().split())

1 2a

out[227]: 1

bout[228]: 2

int可以換成其它需要的型別,左邊可以是任意多個變數

還可以把讀取的值存到乙個列表裡:

list = map(int, raw_input().split())

1 2 3 4 5

list

out[230]: [1, 2, 3, 4, 5]

list[2]

out[231]: 3

python 鍵盤輸入

python鍵盤輸入與其他程式語言基本類似,回車鍵結束輸入 下面來看一段鍵盤輸入年月日,英文輸出示例 1 usr bin env python2 coding utf 8 3 定義英文月份 4 months january february march april may june july aug...

Python模擬鍵盤輸入

2.程式實現 import win32api import win32con win32api.keybd event 17,0,0,0 ctrl鍵位碼是17 win32api.keybd event 86,0,0,0 v鍵位碼是86 win32api.keybd event 86,0,win32c...

Python讀取鍵盤輸入

python提供了兩個內建函式從標準輸入讀入一行文字,預設的標準輸入是鍵盤。如下 raw input 函式從標準輸入讀取乙個行,並返回乙個字串 去掉結尾的換行符 str raw input enter your input print received input is str 這將提示你輸入任意字...