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

歡迎訪問 生活随笔!

生活随笔

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

python

您如何从Python的stdin中读取信息?

發布時間:2025/3/11 python 13 豆豆
生活随笔 收集整理的這篇文章主要介紹了 您如何从Python的stdin中读取信息? 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Python supports following ways to read an input from stdin (standard input),

Python支持以下方式從stdin(標準輸入)讀取輸入 ,

1)使用sys.stdin (1) Using sys.stdin)

sys.stdin is a file-like object on which we can call functions read() or readlines(), for reading everything or read everything and split by newline automatically.

sys.stdin是一個類似于文件的對象,我們可以在其上調用函數read()或readlines() ,以讀取所有內容或讀取所有內容并自動由換行符拆分。

Example:

例:

from sys import stdininput = stdin.read(1) user_input = stdin.readline() amount = int(user_input)print("input = {}".format(input)) print("user_input = {}".format(user_input)) print("amount = {}".format(amount))

Output

輸出量

123 input = 1 user_input = 23amount = 23

2)使用input() (2) Using input())

If the prompt argument is present, it is written to standard output without a trailing newline. The function then reads a line from input, converts it to string (stripping a trailing newline) and returns that.

如果存在提示參數,則將其寫入到標準輸出中,而無需尾隨換行符。 然后,該函數從輸入中讀取一行,將其轉換為字符串(帶末尾的換行符)并返回。

Example:

例:

test = input('Input any text here --> ') print("Input value is: ", test)

Output

輸出量

Input any text here --> Hello Readers! Input value is: Hello Readers!

Recommended posts

推薦的帖子

  • Read input as an integer in Python

    在Python中將輸入讀取為整數

  • Read input as a float in Python

    在Python中以浮點形式讀取輸入

  • Parse a string to float in Python (float() function)

    解析要在Python中浮動的字符串(float()函數)

  • Asking the user for integer input in Python | Limit the user to input only integer value

    要求用戶在Python中輸入整數| 限制用戶僅輸入整數值

  • Asking the user for input until a valid response in Python

    要求用戶輸入直到Python中的有效響應

  • Input a number in hexadecimal format in Python

    在Python中以十六進制格式輸入數字

  • Input a number in octal format in Python

    在Python中以八進制格式輸入數字

  • Input a number in binary format in Python

    在Python中以二進制格式輸入數字

  • How to get the hexadecimal value of a float number in python?

    如何在python中獲取浮點數的十六進制值?

  • Convert an integer value to the string using str() function in Python

    使用Python中的str()函數將整數值轉換為字符串

  • Convert a float value to the string using str() function in Python

    使用Python中的str()函數將浮點值轉換為字符串

  • Input and Output Operations with Examples in Python

    使用Python中的示例進行輸入和輸出操作

  • Taking multiple inputs from the user using split() method in Python

    使用Python中的split()方法從用戶獲取多個輸入

  • Fast input / output for competitive programming in Python

    快速輸入/輸出,可在Python中進行有競爭力的編程

  • Precision handling in Python

    Python中的精確處理

  • Python print() function with end parameter

    帶有結束參數的Python print()函數

翻譯自: https://www.includehelp.com/python/how-do-you-read-from-stdin-in-python.aspx

總結

以上是生活随笔為你收集整理的您如何从Python的stdin中读取信息?的全部內容,希望文章能夠幫你解決所遇到的問題。

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