Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disregarding python variables [duplicate]

Possible Duplicate:
how can i get around declaring an unused variable in a for loop

In Python, particularly with a for-loop, is there a way to not create a variable if you don't care about it, ie the i in this example which isn't needed:

for i in range(10):
    print('Hello')
like image 898
Dean Barnes Avatar asked Nov 28 '22 10:11

Dean Barnes


1 Answers

No, but often you will find that _ is used instead:

for _ in range(10):
    print('Hello')

You only have to be careful when you use gettext.

like image 166
Felix Kling Avatar answered Dec 06 '22 10:12

Felix Kling