014 Data Type: String Type

A string (str)

1.1 What is the string

String is a string of characters, like lamb skewers the same.

1.2 Definitions Method

  • 'Single and "" double quotes and' '' '' 'may represent a string of three quotes
name1 = "xucheng"
print(id(name1))
print(type(name1))
print(name1)

Output:

​ 4418849624

​ <class 'str'>
​ xucheng

name3 = """xu
cheng"""

print(name3)

Output:

trend

cheng

1.3 Use

+ Only string, and the logical comparison *

String concatenation, namely re-apply for a small space a copy of the two strings are then spliced. Instead you YY of the variable value in a small space inside the copy to another variable of a small space, and then stitching.

msg2 = "my name is 'xucheng'"
msg3 = 'my name is "xucheng"'

print(msg2 + msg3)  # my name is 'xucheng'my name is "xucheng"

​ 输出:my name is 'xucheng'my name is "xucheng"

Note: If there are marks within a string, the string inside the quotation marks and wrapping string can not be the same.

name = 'xucheng '
print(name * 5)

​ 输出:xucheng xucheng xucheng xucheng xucheng

Note: multiplication strings are only multiplied by the numbers.

msg1 = 'hello'
msg2 = 'z'

print(msg1 > msg2)

Output: False

Note: The string comparison size comparison of the ASCII code, the future will go into detail.

msg3 = 'zero'
msg4 = 'zx'

print(msg3 > msg4)
print('Z' > 'A')
print('Z' > 'a')
False
True
False

Output:

​ False
​ True
​ False

Note: comparison string is the order of the letters.

Guess you like

Origin www.cnblogs.com/XuChengNotes/p/11271462.html