Python 1-06 string

One, Python string

Wikipedia: A string is a finite sequence of zero or more characters. In Python 3, it has a clearer meaning: a string is an immutable sequence of Unicode code points.

A string sequence is an immutable sequence, which means that it cannot be modified in place like a variable sequence. For example, by concatenating "Cat" on the basis of the string "Python", the string "PythonCat" is obtained. The new string is an independent existence and has no relationship with the basic string "Python".

basename = "Python"
myname = basename + "Cat"
id(basename) == id(myname)  # False

A string is a string of characters enclosed in single quotation marks or double quotation marks. Use triple quotation marks to create multi-line strings. Python does not support single character types, and single characters are also used as a string in Python.

>>> var1 = 'Hello World!'
>>> var2 = "Jack"
>>> var3 = ""                     # 空字符串
>>> var4 = "it's apple"           # 双引号中可以嵌套单引号
>>> var5 = 'This is "PLANE"!'     # 单引号中可以嵌套双引号
>>> var6 = 'what is 'your'name'
SyntaxError: invalid syntax

But single quotes nested single quotes or double quotes nested

Guess you like

Origin blog.csdn.net/weixin_43955170/article/details/112539293