Python知識(shí)分享網(wǎng) - 專業(yè)的Python學(xué)習(xí)網(wǎng)站 學(xué)Python,上Python222
Python使用input獲取用戶輸入
發(fā)布于:2023-09-11 14:43:04

Python 7天快速入門完整視頻教程https://www.bilibili.com/video/BV1o84y1Z7J1

 

Python使用input獲取用戶輸入

 

 

input()函數(shù)用于向用戶生成一條提示,然后獲取用戶輸入的內(nèi)容。由于input()函數(shù)總會(huì)將用戶輸入的內(nèi)容放入字符串中,因此用戶可以輸入任何內(nèi)容,input()函數(shù)總是返回一個(gè)字符串。我們可以通過int() float()方法來轉(zhuǎn)換類型。

案例:

 

"""
    使用input獲取用戶輸入
"""

name = input("請(qǐng)輸入您的姓名:")
print(name, type(name))

age = input("請(qǐng)輸入您的年齡:")
age = int(age)
print(age, type(age))

height = input("請(qǐng)輸入您的身高(cm):")
height = float(height)
print(height, type(height))

 

 

 

轉(zhuǎn)載自: