-1

I've just started learning Python. The book I'm studying has the code below. I understand the general meaning and the end result but I don't understand where P came from and what it does. Could you explain it to me, please?

parts = ['43', '44', '45\n']
numbers = [int(P) for P in parts]
John Kugelman
  • 349,597
  • 67
  • 533
  • 578
  • The `P` is an internal variable in what is called a "list comprehension". The line `numbers = [int(P) for P in parts]` is just a compressed for-loop – James Dec 12 '19 at 11:36

1 Answers1

0

In your case P is just a variable where you use to get each individual part(P) from list of parts.

Ali Beyit
  • 431
  • 1
  • 6
  • 19