日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python函数示例_使用Python中的示例的input()函数

發布時間:2025/3/11 python 54 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python函数示例_使用Python中的示例的input()函数 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

python函數示例

Python input()函數 (Python input() function)

input() function is a library function, it is used to get the user input, it shows given message on the console and wait for the input and returns input value in string format.

input()函數是一個庫函數,用于獲取用戶輸入,它在控制臺上顯示給定的消息并等待輸入,并以字符串格式返回輸入值。

Syntax:

句法:

input(prompt)

Parameter(s): promot – a string value/message that will display on the console.

參數: promot –將在控制臺上顯示的字符串值/消息。

Return value: str – it returns user input in string format.

返回值: str –以字符串格式返回用戶輸入。

Example:

例:

Input:text = input("Input any text: ")# if user input is "Hello world!"print("The value is: ", text)Output:Input any text: Hello world!

Example 1: Input a string and print it and its type

示例1:輸入一個字符串并打印它及其類型

# python code to demonstrate example # of input() function# user input text = input("Input any text: ")# printing value print("The value is: ", text)# printing type print("return type is: ", type(text))

Output

輸出量

Input any text: Hello world! The value is: Hello world! return type is: <class 'str'>

Example 2: Input different of types of values and print them along with their types

示例2:輸入不同類型的值,并將其與它們的類型一起打印

# python code to demonstrate example # of input() function# input 1 input1 = input("Enter input 1: ") print("type of input1 : ", type(input1)) print("value of input1: ", input1)# input 2 input2 = input("Enter input 2: ") print("type of input2 : ", type(input2)) print("value of input2: ", input2)# input 3 input3 = input("Enter input 3: ") print("type of input3 : ", type(input3)) print("value of input3: ", input3)

Output

輸出量

Enter input 1: 12345 type of input1 : <class 'str'> value of input1: 12345 Enter input 2: 123.45 type of input2 : <class 'str'> value of input2: 123.45 Enter input 3: Hello [email?protected]#$ type of input3 : <class 'str'> value of input3: Hello [email?protected]#$

輸入整數和浮點值 (Input integer and float values)

There is no direct function that can be used to take input in either in an integer value or in a float value.

沒有直接函數可用于以整數值或浮點值進行輸入。

input() function takes an input from the user of any type like integer, float, string but returns all values in string format. If we need values in an integer or float types, we need to convert them.

input()函數從用戶獲取任何類型的輸入,例如整數,浮點數,字符串,但以字符串格式返回所有值。 如果我們需要整數或浮點類型的值,則需要對其進行轉換。

To convert input in an integer, we use int() function.

為了將輸入轉換為整數,我們使用int()函數 。

To convert input in a float, we use float() function.

為了將輸入轉換為浮點數,我們使用float()函數 。

Example 3: Python code to input integer and float values

示例3:用于輸入整數和浮點值的Python代碼

# python code to demonstrate example # of input() function# input an integer value num = int(input("Enter an integer value: ")) print("type of num: ", type(num)) print("value of num: ", num)# input a float value num = float(input("Enter a float value: ")) print("type of num: ", type(num)) print("value of num: ", num)

Output

輸出量

Enter an integer value: 12345 type of num: <class 'int'> value of num: 12345 Enter a float value: 123.45 type of num: <class 'float'> value of num: 123.45

翻譯自: https://www.includehelp.com/python/input-function-with-example.aspx

python函數示例

總結

以上是生活随笔為你收集整理的python函数示例_使用Python中的示例的input()函数的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。