String manipulation

tutorial


formatted printing:
  print "%2d" % number,
         ^^^  ^       ^--- suppress line break
          |   |-- separate format and number(s)
          |
          |--- format

line="0 243 7"
words=line.split(' ')
index=int(words[0]) # string to number
value=int(words[1])

number=0b110011
print hex(number)
print bin(number)

Hexadecimal and binary notation:

In []: bin(22)
Out[]: '0b10110'

In []: bin(22)[0]
Out[]: '0'

In []: bin(22)[1]
Out[]: 'b'

In []: bin(22)[2]
Out[]: '1'

In []: bin(22)[2:]
Out[]: '10110'
convert string to int: int(string)