python- 对input 进行split()

# Python program showing how to 
# multiple input using split 
  
# taking two inputs at a time 
x, y = input("Enter a two value: ").split() 
print("Number of boys: ", x) 
print("Number of girls: ", y) 
print() 
  
# taking three inputs at a time 
x, y, z = input("Enter a three value: ").split() 
print("Total number of students: ", x) 
print("Number of boys is : ", y) 
print("Number of girls is : ", z) 
print() 
  
# taking two inputs at a time 
a, b = input("Enter a two value: ").split() 
print("First number is {} and second number is {}".format(a, b)) 
print() 
  
# taking multiple inputs at a time  
# and type casting using list() function 
x = list(map(int, input("Enter a multiple value: ").split())) 
print("List of students: ", x)

Enter a two value: 4 5
Number of boys: 4
Number of girls: 5

Enter a three value: 8 4 4
Total number of students: 8
Number of boys is : 4
Number of girls is : 4

Enter a two value: 4 4
First number is 4 and second number is 4

Enter a multiple value: 1 2 3 4
List of students: [1, 2, 3, 4]
1


版权声明:本文为weixin_43012796原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。