Q:

How to bypass base-8 number identification in python?

I was doing an exercide I saw somewhere online that consisted of manipulating binary sequences (for example swaping every one by a zero and every zero for a one), at somepoint in the code, i wanted to print 0101 like this:
seq = 0101
print seq

And the output was 65 instead of 0101, I discovered this is because the 0 in the begginning of a integer identifies a base-8 number, how can I bypass this?

A:

You can't. When you put 0101, it automatically translates to the value of oct(101). You can save it as binary:
seq = 0b101

but this does not keep the leading 0. Your best bet would be to save it as a string.
seq = "0101"
swapped = ''.join(['1' if b in '0' else '0' for b in seq]) # or maketrans
print(swapped)  # => 1010
print(int(swapped, 2))  # => 10

