Post

Python Programming
Python Programming@PythonPr·
Python Question / Quiz; What is the output of the following Python code, and why? Comment your answers below!
Python Programming tweet media
English
21
13
108
10K
Sergei Kotau
Sergei Kotau@sergeikotau·
Answer: B) Developers › List comprehension filters: if len(i) > 6 › 'Python' = 6 chars (NO), 'Developers' = 10 (YES) › result = ['Developers'] › *result unpacks = print('Developers') For beginners: unpacking gets each element and passes as separate arguments. x = ['a','b'], print(*x) = print('a','b')
English
0
0
14
412
Ayush
Ayush@iAyushCodes·
@PythonPr Answer: B i for i in List if len(i)>6 Think as if a pointer is going over all the elements present inside the List If the length of the element is more than 6, it will add that element inside the result list *result : it unpacks the result list elements and prints it Developer
English
0
0
3
194
Biel Men
Biel Men@BielMenHaha·
@PythonPr Will print "developers" The asterisc means all the itens in the iterable should be used as argument, not as list-argument. So, the only string greather than 6 characters is "developer", and the only one going to be parsed as argument to be printed.
English
0
0
3
335
Omo Yewa
Omo Yewa@AceKelm·
@PythonPr B. Developers. The only element with length greater than 6 going by the operator in line 2 is 'Developers'. Hence the result.
English
0
0
1
198
共有