Python Forum

Full Version: help with list
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
when I print the value of my list, he print b'value' and I don't know why the program does that. I think is binairy, but I need the value only.
It's not binary,but bytes.
Where dos data in you list come from?
All data that come into Python 3 most have encoding,if not it will be bytes.
This is because of Unicode,which was one biggest changes moving to Python 3.

Can convert with decode() encode().
>>> lst = [b'value', b'hello', b'9999']
>>> lst[0]
b'value'
>>> type(lst[0])
<class 'bytes'>

>>> # To str also default Unicode text Python 3
>>> lst[0].decode() # Same as .decode('utf-8')
'value'
>>> [i.decode() for i in lst]
['value', 'hello', '9999']
Can also work with bytes,eg string method works.
>>> lst[0].upper()
b'VALUE'
thank for the help, is very well explained.