新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)Python教程:Pythoninput()
input()函數(shù)有助于接受用戶的輸入,并以字符串格式返回輸出。用戶可以輸入字符串或數(shù)字格式。

10年積累的成都做網(wǎng)站、網(wǎng)站建設(shè)、外貿(mào)營銷網(wǎng)站建設(shè)經(jīng)驗(yàn),可以快速應(yīng)對客戶對網(wǎng)站的新想法和需求。提供各種問題對應(yīng)的解決方案。讓選擇我們的客戶得到更好、更有力的網(wǎng)絡(luò)服務(wù)。我雖然不認(rèn)識你,你也不認(rèn)識我。但先網(wǎng)站設(shè)計(jì)制作后付款的網(wǎng)站建設(shè)流程,更有衛(wèi)東免費(fèi)網(wǎng)站建設(shè)讓你可以放心的選擇與我們合作。
**input([prompt])** #Where prompt is a string value
輸入()參數(shù):
接受單個(gè)參數(shù)。無論用戶鍵入什么,它都將作為輸入?yún)?shù)。
| 參數(shù) | 描述 | 必需/可選 |
|---|---|---|
| 提示 | 寫入標(biāo)準(zhǔn)輸出(通常是屏幕)的字符串,不帶尾隨換行符 | 可選擇的 |
輸入()返回值
input()函數(shù)實(shí)際上是對輸入字符串進(jìn)行求值,并嘗試將其作為 Python 代碼運(yùn)行,輸出作為字符串返回。
| 投入 | 返回值 | | 線 | 通過移除尾部換行符來創(chuàng)建字符串 | | 如果電滲流 | 它會引發(fā) EOFError 異常。 |
Python 中input()方法的示例
示例 1:輸入()在 Python 中是如何工作的?
# get input from user
inputString = input()
print('The inputted string is:', inputString)
輸出:
Python is interesting.
The inputted string is: Python is interesting 示例 2:通過提示獲取用戶輸入
# get input from user
inputString = input('Enter a string:')
print('The inputted string is:', inputString)
輸出:
Enter a string: Python is interesting.
The inputted string is: Python is interesting 示例 3:輸入員工詳細(xì)信息
# take three values from user
name = input("Enter Employee Name: ")
salary = input("Enter salary: ")
company = input("Enter Company name: ")
# Display all values on screen
print("\n")
print("Printing Employee Details")
print("Name", "Salary", "Company")
print(name, salary, company)
輸出:
Enter Employee Name: Jessa
Enter salary: 8000
Enter Company name: Google
Printing Employee Details
Name Salary Company
Jessa 8000 Google 示例 4:計(jì)算兩個(gè)輸入整數(shù)相加的程序
# convert inout into int
first_number = int(input("Enter first number ")) sec second number "))
print("\n")
print("First Number:", first_number)
print("Second Number:", second_number)
sum1 = first_number + second_number
print("Addition of two number is: ", sum1)
輸出:
Enter first number 28
Enter second number 12
First Number: 28
Second Number: 12
Addition of two number is: 40 當(dāng)前名稱:創(chuàng)新互聯(lián)Python教程:Pythoninput()
本文網(wǎng)址:http://www.dlmjj.cn/article/dghhsge.html


咨詢
建站咨詢
