簡體   English   中英

如何使我的輸入在一行中(python)

[英]How do I make my input be in one line (python)

而不是它

7
3
2

我該怎么做

7,3,2

這不是我的 output,只是我的輸入

你可以這樣做:

# 1 input request
res = input()

# split into a numbers array
numbers = res.split(',')

# remove any whitespace next to the numbers
numbers = [number.strip() for number in numbers]

這些都使用內置的 python 函數,在官方 python 文檔中有很好的記錄。

numbers = input("enter numbers")
#takes in the input

numbers = numbers.split(",")
#splits the input into a list of the values

  

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM