input().split(separator, maxsplit)
例子 :展示了如何使用 split 進行多重輸入的Python 程序一次接受兩個輸入x, y = input("Enter two values: ").split()
print("Number of boys: ", x)
print("Number of girls: ", y)
print()
一次接受三個輸入x, y, z = input("Enter three values: ").split()
print("Total number of students: ", x)
print("Number of boys is : ", y)
print("Number of girls is : ", z)
print()
一次接受兩個輸入a, b = input("Enter two values: ").split()
print("First number is {} and second number is {}".format(a, b))
print()
一次接受多個輸入# and type casting using list() function
x = list(map(int, input("Enter multiple values: ").split()))
print("List of students: ", x)
輸出:x, y = [int(x) for x in input("Enter two values: ").split()]
print("First Number is: ", x)
print("Second Number is: ", y)
print()
一次接受三個輸入x, y, z = [int(x) for x in input("Enter three values: ").split()]
print("First Number is: ", x)
print("Second Number is: ", y)
print("Third Number is: ", z)
print()
一次接受兩個輸入x, y = [int(x) for x in input("Enter two values: ").split()]
print("First number is {} and second number is {}".format(x, y))
print()
一次接受多個輸入x = [int(x) for x in input("Enter multiple values: ").split()]
print("Number of list is: ", x)
輸出 :# 一次接受多個輸入,用逗號分隔
x = [int(x) for x in input("Enter multiple value: ").split(",")]
print("Number of list is: ", x)
感謝大家的閱讀,有什麼問題的話可以在評論中告訴我。希望大家能夠給我來個點贊+收藏+評論 ,你的支持是海海更新的動力!後面我會持續分享前端 & 後端相關的專業知識。Record some problems encounter
Active address : Graduation se