Basic data types
Python has five standard data types:
Numbers (digital)
String (String)
List (lists)
Tuple (tuple)
Dictionary (dictionary)
The shell seems to have no obvious data type to differentiate
Python supports four different numeric types:
The following highlights the three data types of strings, lists, tuples and dictionaries
string
The focus is on the interception function:
#!/bin/python#string testingstr= "AABBCCDD" Print (str) print (str[0]) print (Str[2:5]) print (str*2) print (str+ "Join test ")
Output:
Aabbccdd
A
Bbc
Aabbccddaabbccdd
Aabbccddjoin Test
Kerry
Eva
111
222
The shell string is truncated as follows:
Start with the first few characters on the left, and the number of characters
Echo ${var:0:5}
Where 0 means the first character on the left begins, and 5 indicates the total number of characters
Only the number, not the end index value, and the shell can also intercept according to #,%,##,%%.
the first character on the left side of the shell is denoted by 0, and the first character on the right is denoted by 0-1 .
In Python, the first one on the left is 0, the first on the right is-1
< Span style= "Color:rgb (70, 70, 70); Font-family: Song body; font-size:14px; line-height:21px; Background-color:rgb (211, 235, 239); " > Starting from the first few characters on the right, and the number of characters echo ${var:0-7:3}
List
The list is the most frequently used data type in Python.
A list can accomplish the data structure implementation of most collection classes. It supports characters, numbers, and even strings that can contain lists (so-called nesting).
The list is identified by []. Is the most common composite data type of Python. See this code to understand.
The list of values can also be used to split the variable [head subscript: Tail subscript], you can intercept the corresponding list, from left to right index default 0, starting from right to left index default-1, subscript can be empty to take the head or tail.
The plus sign (+) is the list join operator, and the asterisk (*) is a repeating operation. The following example
[Email protected] ~]$ VI testall.py #!/bin/pythonname=["Kerry", "Eva", 111,222]name2=["Eva", 333]for element in Name:pri NT (Element) print ("All elements:"), Nameprint ("The second element was:"), Name[2]print ("The 1,3,sub is:"), Name[1:3]// Open interval Print ("Double:"), Name*2print ("Join:"), name+name2
Python data types and syntax