0

What's the use of _ in python?

I often see for loop written as for _ in range(5): instead of for i in range(5): What's the difference and what are some other uses of '_'? Thanks '_'

17th Feb 2020, 6:07 PM
Abhishek Tandon
Abhishek Tandon - avatar
7 odpowiedzi
+ 1
fascinating/interesting...: for _ in range(10): print(_ * 2) I was aware of using the "_" for tuple/list unpacking. e.g:- a, _, _, _, b = (10, 11, 12, 13, 14) print(a, b) #or c, *_, d = (10, 11, 12, 13, 14) print(c, d)
17th Feb 2020, 6:48 PM
rodwynnejones
rodwynnejones - avatar
0
Mirielle👽 Could you explain your second point with an example?
17th Feb 2020, 6:44 PM
Abhishek Tandon
Abhishek Tandon - avatar
0
Mirielle👽 Then what is with '__init__' there we use '_' as well, don't we?
17th Feb 2020, 6:47 PM
Abhishek Tandon
Abhishek Tandon - avatar
0
rodwynnejones pretty interesting! thanks for sharing
17th Feb 2020, 6:51 PM
Abhishek Tandon
Abhishek Tandon - avatar