Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,971 questions

51,913 answers

573 users

How to convert bytes to string in Python

12 Answers

0 votes
b = bytes("python", "ascii")
print(b)

s = b.decode("ascii")
print(s)



 
'''
run:
 
b'python'
python
 
'''

 



answered Oct 18, 2020 by avibootz
0 votes
s = b"python".decode("utf-8") 

print(s)



 
'''
run:
 
python
 
'''

 



answered Oct 18, 2020 by avibootz
edited May 10, 2024 by avibootz
0 votes
bytes = b'\x61\x62'

s = bytes.decode()

print(s)



'''
run:

ab

'''

 



answered Apr 9, 2021 by avibootz
0 votes
bytes = b'\xF1\x62'

s = bytes.decode('utf-8', 'ignore')

print(s)



'''
run:

b

'''

 



answered Apr 9, 2021 by avibootz
0 votes
bytes = b'\xF1\x62'

s = bytes.decode('utf-8', 'replace')

print(s)



'''
run:

�b

'''

 



answered Apr 9, 2021 by avibootz
0 votes
bytes = b'\xF1\x62'

s = bytes.decode('utf-8', 'backslashreplace')

print(s)



'''
run:

\xf1b

'''

 



answered Apr 9, 2021 by avibootz
0 votes
bytes = b'\x61\x62\x63'

s = "".join([chr(_) for _ in bytes])

print(s)



'''
run:

abc

'''

 



answered Apr 9, 2021 by avibootz
0 votes
bytes = b'\x61\x62\x63'

s = "".join(map(chr, bytes))

print(s)



'''
run:

abc

'''

 



answered Apr 9, 2021 by avibootz
0 votes
by = [97, 98, 99, 100]
 
s = "".join(map(chr, by))
 
print(s)
 


'''
run:
 
abcd
 
'''

 



answered May 10, 2024 by avibootz
0 votes
s = str(b'python', "utf-8")
 
print(s)
 
 
 
'''
run:
 
python
 
'''

 



answered May 10, 2024 by avibootz
0 votes
by = bytes(b"python")
 
s = by.decode("ascii")
 
print(s)
 
 

'''
run:
 
python
 
'''

 



answered May 10, 2024 by avibootz
0 votes
s = b'\x49\x53\x55'.decode('utf-8')
 
print(s)
 
 
 
'''
run:
 
ISU
 
'''

 



answered May 10, 2024 by avibootz

Related questions

4 answers 358 views
358 views asked Sep 10, 2018 by avibootz
1 answer 92 views
1 answer 141 views
141 views asked Apr 25, 2021 by avibootz
2 answers 166 views
166 views asked Apr 9, 2021 by avibootz
3 answers 197 views
197 views asked Apr 9, 2021 by avibootz
3 answers 231 views
231 views asked Apr 9, 2021 by avibootz
...