One more tip - if anyone is learning Python on HackerRank, knowing this is critical for starting out.
I'm trying to understand this code:
stamps = set()
for _ in range(int(input())):
print('underscore is', _)
stamps.add(raw_input().strip())
print(stamps)
Output:
>>>2
underscore is 0
>>>first
set(['first'])
underscore is 1
>>>second
set(['second', 'first'])
I put 2 as the first raw input. How does the function know that I'm only looping twice? This is throwing me off because it isn't the typical...for i in xrange(0,2) structure.
At first my thinking was the underscore repeats the last command in shell. So I added print statements in the code to see the value of underscore...but the values just show the 0 and 1, like the typical loop structure.
I read through this post already and I still can't understand which of those 3 usages of underscore is being used.
What is the purpose of the single underscore "_" variable in Python?
I'm just starting to learn Python so easy explanations would be much appreciated!