
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
How would you convert string to bytes in Python 3?
To convert string to bytes in Python 3, you can use the encode() function from the string class. For example,
>>> s = u"HellΘ WΘrld" >>> s.encode('utf-8') 'Hell\xce\x98 W\xce\x98rld'
- Related Articles
- How can I convert bytes to a Python string?
- Convert bytes to a string in java
- Convert String to UTF-8 bytes in Java
- How would you make a comma-separated string from a list in Python?
- How can I convert a bytes array into JSON format in Python?
- How to convert string to binary in Python?
- How to convert list to string in Python?
- How to convert int to string in Python?
- How to convert a string to dictionary in Python?
- Program to convert KiloBytes to Bytes and Bits in C++
- How to convert string to JSON using Python?
- How to get the length of a string in bytes in JavaScript?
- How do you convert a string to a character array in JavaScript?
- How to convert hex string into int in Python?
- Convert String to Tuple in Python

Advertisements