a = [int(a) for a in input().strip().split(' ')]
Can anyone explain what this line of code does.
Thanks
Answers
Answered by
1
Answer:
See below.
Explanation:
The code given is,
a = [ int( a ) for a in input( ).strip( ).split( ' ' ) ]
The code takes in an input ( as a String ). This String is then splitted into parts which are separated by spaces( for example "23 34 45" becomes [ 23 , 34 , 45 ] ).
Going in deep,
int( a ) : It ensures that the String block ( the splitted part ) has an integer data type.
input( ).strip( ).split( ' ' ) : Takes an input, removes empty spaces from the beginning and end, and finally splits it by spaces ( ' ' )
All these integers are then stored in a list.
Try this,
>>> a = [ int( a ) for a in input('Input ').strip().split(' ')]
Input 45 67 89
>>> print( a )
[45, 67, 89]
Similar questions