简体   繁体   中英

how to take multiple inputs in python from same line with different rules

I am trying to assign 3 variables values from a single line in python, first variable gets the first word, second variable 2nd word and rest of the string to the 3rd variable

tried using

var1,var2,var3 = input().split()

but i keep running into Packaging error

also i want to ensure even if variable is not given any value, it won't run into an error

Use a single variable since the split() method will return a list. If no parameter is supplied, it will try to split at spaces. Therefore:

vars = "a b c".split()
print(vars)

will output ['a', 'b', 'c']
That way you can just iterate over your values, count them, or whatever fits your need.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM