1、The common data types in Python are three: integer, float, and string.
Integer is what we commonly see in mathematics, such as10、20、30。Float is a number with a decimal point, such as12.345。
String type is an ordered sequence of characters used to represent text information. In my personal understanding, characters are actually images. In various foreign software inventions, Chinese characters are all strings, which means they are all images.
2、How do we tell the software inPythonthat this group of data or this text is a string?
Answer: InPython, strings are represented by two double quotes (” “) or two single quotes (‘ ’).
3、A string is a sequence of characters and can be searched by individual characters or character segments.
A string includes two indexing systems: forward incrementing index and backward decrementing index.
If the length of the string isL, the forward incrementing index uses0to represent the index of the leftmost character, and the index of the rightmost character isL-1。For example, in the string “阿盼爱吃草莓”, in forward incrementing,0represents the character “阿”,3represents the character “爱”,5represents the character “莓”.
If the length of the string isL, the backward decrementing index uses-1to represent the index of the rightmost character, and the index of the leftmost character is-L。For example, in the string “阿盼爱吃草莓”, in backward decrementing,-1represents the character “莓”,-3represents the character “吃”,-6represents the character “阿”.
These two retrieval methods are often mixed by programmers inPython.
Pythonstrings can use the[N:M]format to obtain a substring, which indicates the substring fromNtoM(excludingM).
For example:“阿盼爱吃草莓”[0:4]represents “阿盼爱吃”; “阿盼爱吃草莓”[0:-1]represents “阿盼爱吃草”.