课程: Advanced Python (2018)

今天就学习课程吧!

今天就开通帐号,24,600 门业界名师课程任您挑!

Strings vs. bytes

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…

内容