Basic Python-string, basic python string
Basic string syntax
Print () Output
In Python 3, strings are Unicode encoded. That is to say, Python strings support multiple languages.
Chr () encoding into characters <----------------------------------->ord()
Integer representation of Characters
<---------------------->
Byte Data Representation
x = b'ABC'
Len () str contains characters
To enable the python file to be read by UTF-8, add two lines at the beginning of the file.
#!/usr/bin/env python3 # -*- coding: utf-8 -*-
The first line of comment is to tell the Linux/OS X system that this is a Python executable program and will be ignored in Windows; The second line of comment is to tell the Python interpreter to read the source code according to the UTF-8 encoding, otherwise, the Chinese output you write in the source code may be garbled. Declaring the UTF-8 code doesn't mean your.py The file is UTF-8 encoded and must be ensured that the text editor is using the UTF-8 without BOM encoding: |
% String formatting
Similar'Dear xxx, hello! Your phone bill for xx months is xx, and your balance is xx'
And so on, and the content of xxx changes according to the variable. Therefore, a simple format method is required.
Here, % is used to format the string.
%s
String replacement,%d
Replace the value with an integer.
Two % represents a %