What underscore is doing in python | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
0

What underscore is doing in python

for _ in range():

3rd Jan 2021, 5:06 PM
Gayane Chilingaryan
Gayane Chilingaryan - avatar
4 Antworten
+ 6
it is quite common to use this as "disposable loop variable" when you do not need the loop-variable inside the loop: for _ in range(10): print("Hello world") other than a code like this where you use the loop-variable inside the loop: for i in range(10): do_something(i)
3rd Jan 2021, 5:10 PM
Martin Ed
Martin Ed - avatar
+ 2
_ is just a local variable name for the loop. Instead of _ it could be i, j, k or any other name
3rd Jan 2021, 5:10 PM
Lisa
Lisa - avatar
0
Thanks a lot
3rd Jan 2021, 5:12 PM
Gayane Chilingaryan
Gayane Chilingaryan - avatar
0
def fit(self, xTest, yTest) for _ in (): self.update_weights()
3rd Jan 2021, 5:16 PM
Gayane Chilingaryan
Gayane Chilingaryan - avatar