I’m just getting started with python. Can somebody interpret line 2 of the following code snippet? I don’t understand the `num` bit. I tried to replace the backtick character with a single tick ', but then it broke. Just a detailed explanation of that line would be great.
loop_count = 1000000
irn = ''.join([`num` for num in range(loop_count)])
number = int(irn[1]) * int(irn[10]) * int(irn[100]) * int(irn[1000]) * int(irn[10000]) * int(irn[100000]) * int(irn[1000000])
print number
Backticks are a deprecated alias for the
repr()builtin function, so the second line is equivalent to the following:This uses a list comprehension to create a list of strings representing numbers, and then uses
''.join()to combine that list of strings into a single string, so this is equivalent to the following:Note that I used
repr()here to be consistent with the backticks, but you will usually seestr(num)to get the string representation of an int (they happen to be equivalent).