From the course: Advanced Python

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Strings vs. bytes

Strings vs. bytes - Python Tutorial

From the course: Advanced Python

Start my 1-month free trial

Strings vs. bytes

- [Instructor] In Python 3, there are very important differences between the notions of strings and bytes. And it's important to understand this distinction. A string in Python 3 is a sequence of Unicode characters, while bytes are a sequence of raw eight-bit values. It's important to understand this because you can't just treat a string as if it were an array of ASCII eight-bit values. So, let's take a look at this in practice. Here in VS Code I have my strings_start.py file open and I have defined two variables here, b and s. So, b is a sequence of bytes and s is a string. And I can print out each one to see what their values are. So, I've got VS Code set up to just run my Python directly, so I'm gonna click on the Debug tab and I'm going to run this. And you can see in the output that the first is a sequence of bytes, as noted by the little b character right there. And the second print statement prints out this is a string. Now, if you're not using VS Code and you want to run this…

Contents