0

I was trying to make a code that allows multiple user inputs in different variables in only one line in Python. I've studied a bit of list comprehension, but I can't understand how the code below works.

a,b,c = [int(a) for a in input().split()]

Why is the output an integer value of a, b, and c if only a is being put into the loop?

prynpo
  • 1
  • Welcome to Stack Overflow. I think you are overthinking this. If I show you the code `a, b, c = [1, 2, 3]`, can you understand how that works? If I show you the code `a, b, c = [1, 2, 3, 4]`, you expect an error, right? Now, when you try the code `[int(a) for a in input().split()]` by itself, what do you get? A list, right? So - if that list *happens to contain* three values, what should happen? If it contains some other number of values, what should happen? (the `a` in the list comprehension has **nothing to do with** the `a` on the left-hand side of the `=`.) – Karl Knechtel Sep 13 '22 at 22:48
  • @khelwood is there really not a better version of that question? :( – Karl Knechtel Sep 13 '22 at 22:50
  • @Karl Probably somewhere – khelwood Sep 13 '22 at 22:52

0 Answers0