

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is a Python bytestring?
A string is a sequence of characters; these are an abstract concept, and can't be directly stored on disk. A byte string is a sequence of bytes - things that can be stored on disk. The mapping between them is an encoding - there are quite a lot of these (and infinitely many are possible) - and you need to know which applies in the particular case in order to do the conversion, since a different encoding may map the same bytes to a different string. For example, the same byte string can represent 2 different strings in 2 different encodings. For example,
>>> b'\xcf\x84o\xcf\x81\xce\xbdo\xcf\x82'.decode('utf-16') '蓏콯캁澽苏' >>> b'\xcf\x84o\xcf\x81\xce\xbdo\xcf\x82'.decode('utf-8') 'τoρνoς'
Once you know which encoding to use, you can use the .decode() method of the byte string to get the right character string from it. The .encode() method of a character string goes the opposite way and encodes the character string as a byte string.
- Related Questions & Answers
- Convert byteString key:value pair of dictionary to String in Python
- What is a namespace in Python?
- What is a Tick in python?
- What is a TimeTuple in Python?
- What is a metaclass in Python?
- What is a regular expression in Python?
- What is a dot operator in Python?
- What is the difference between a python module and a python package?
- What is a file descriptor used in Python?
- What is a sequence data type in Python?
- What is immutable in Python?
- What is @ operator in Python?
- What is iterweekdays() in python?
- What is itermonthdates() in python?
- What is itermonthdays2() in python?