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

Prodentim Probiotics Specially Designed For The Health Of Your Teeth And Gums

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Teach Your Child To Read

Powerful WordPress hosting for WordPress professionals

Disclosure: My content contains affiliate links.

31,104 questions

40,777 answers

573 users

How to convert string to bytes in Python

4 Answers

0 votes
s = "python"

by = bytes(s, "ascii")

print(by)


'''
run:

b'python'

'''

 





answered Sep 10, 2018 by avibootz
0 votes
s = "python"

by = bytes(s, 'utf-8')

print(by)

 
'''
run:

b'python'

'''

 





answered Dec 7, 2018 by avibootz
0 votes
s = "python"
 
b = bytes(s, encoding = "utf-8")
 
print(b)
 
 
 
'''
run:
 
b'python'
 
'''

 





answered Apr 11 by avibootz
0 votes
s = "python"
 
b = s.encode(encoding="utf-8")
 
print(b)
 
 
 
'''
run:
 
b'python'
 
'''

 





answered Apr 11 by avibootz

Related questions

1 answer 62 views
8 answers 163 views
163 views asked Oct 18, 2020 by avibootz
1 answer 107 views
107 views asked Sep 10, 2018 by avibootz
3 answers 152 views
152 views asked Sep 28, 2017 by avibootz
...