python输入split
The task is to take multiple inputs from the user, for this we can use split() method.
任务是从用户那里获取多个输入 ,为此,我们可以使用split()方法 。
split()方法 (split() method)
split() method is a library method in Python, it accepts multiple inputs and brakes the given input based on the provided separator if we don’t provide any separator any whitespace is considered as the separator.
split()方法是Python中的一种库方法,如果我们不提供任何分隔符,则任何空白都被视为分隔符,它接受多个输入并根据提供的分隔符制动给定输入。
Syntax:
句法:
input().split([separator], [maxsplit])
Here, separator and maxsplit are the optional parameters, they can be used for the specified purposes.
在这里, separator和maxsplit是可选参数,它们可用于指定目的。
Example without using separator
不使用分隔符的示例
# input two integer numbers and print them
a, b = input('Enter two integer numbers: ').split()
print("a = ",a, ",b = ",b)
# input name, age and percentages of the student
# and print them
name, age, perc = input("Enter student's details: ").split()
print("Name: ", name)
print("Age: ", age)
print("Percentage: ", perc)
Output
输出量