python3鍵盤輸入

2022-07-26 19:39:10 字數 710 閱讀 7317

1、指令碼

# -*- coding: utf-8 -*-

print("今年是哪一年?"),

year = input("年份:")

print ("jin nian de shengxiao shi :"),

zodiac = input("屬相:")

print("今年幾歲了?"),

age = input("age:")

print ("今年是 %s年,%s年,doudou %s 歲了"%(year,zodiac,age))

#age = int(age),------直接int(age)會報錯

age = int(input("age:"))

print ("今年是 %s年,%s年,doudou %d 歲了"%(year,zodiac,age))

print ("今年是 %s年,%s年,doudou %d 歲了"% (

year,zodiac,age))

2、執行結果

備註:1、python3鍵盤輸入需要用input(),python2鍵盤輸入用raw_input()

2、input()會將使用者輸入的所有內容當做字串來對待

3、age = int(input("age:")),強行將字串轉換未整形

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 這將提示你輸入任意字...