What's the use of _ in python? | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
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
Infinity
Infinity - avatar
4 Antworten
+ 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
Infinity
Infinity - avatar
0
Mirielle👽 Then what is with '__init__' there we use '_' as well, don't we?
17th Feb 2020, 6:47 PM
Infinity
Infinity - avatar
0
rodwynnejones pretty interesting! thanks for sharing
17th Feb 2020, 6:51 PM
Infinity
Infinity - avatar