The key points of Python strings are as follows:
1. Some quotation mark-delimited characters
You can think of strings as a data type of Python. In Python single An array of characters or a collection of consecutive characters between quotes or double quotes. The most commonly used quotation marks in python are ('') and (""). The functionality of both is the same, the actual content of the string is the characters between the quotes, not the quotes themselves.
2. Indivisible character type
String is the only literal character sequence type. However, characters themselves are not a type, so strings are the most basic unit of character storage operations.
3. The string formatting operator (%) provides functions similar to printf()
The string formatting operator provides a way to create custom characters based on a variety of output types A flexible method for strings, it provides an interface similar to C/C++ formatting operations.
4. Triple quotation marks
Special characters such as line feed, carriage return or tab key can be included in the triple quotation marks. Triple quotes are actually three single quotes (''' ''') or double quotes (""" """) on both sides
5. The original string uses its original meaning for each special character
This is very useful in defining regular expressions.
6.Python strings are not terminated by NUL or '\0'
Strings in C language use '\0' as the terminator to prevent out of bounds. But in python, no, you don't need to worry about whether the terminator has been added. The string value contains what you defined and nothing else.
The above is the detailed content of Summarize the key points of Python strings. For more information, please follow other related articles on the PHP Chinese website!