In order to understand you need to decompose.
Binary representation of 12
format allows you to give the binary representation of 12:
>>> '{0:b}'.format(12)
'1100'
You could also use bin but '0b' is append at the beginning:
>>> bin(12)
'0b1100'
However, you could write bin(12)[2:] (as suggested in another answer).
Iteration over a string
You can iterate over each character of a string using a loop by doing:
for x in '1100':
The x in this for loop will take the successive characters of the string: '1', '1', '0', '0'.
List comprehension
And finally, [... for x in ...] is a list-comprehension. That will create a new list using the for.
[int(x) for x in '1100']
is equivalent to:
list(map(int, '1100'))
and:
list(map(int, ['1', '1', '0', '0']))
or:
l = []
for x in '1100':
l.append(int(x))
Loop variant?
Your question is actually: what is the loop variant here?
Well, in Python, the for is in fact more a foreach. Let's take as an example for x in [3, 2, 10]. x will successively take the values 3, 2 and 10.
If we want something close to the C-style for-loop:
// C for-loop:
for (int i = 0; i < 10; i++)
We write:
# Python for-loop:
for i in range(10):
range(10) returns something iterable and i will take the successive values given by range.
Back to your example, there is no "loop variant" but if you need one, you can use enumerate:
for i, x in enumerate('1100'):
print(i, x)
Will give:
(0, '1')
(1, '1')
(2, '0')
(3, '0')