
When discussing data types in Python, we must start with the standard data types. The standard data types in Python are as follows:

Numeric data types are used to store numerical values.
They are immutable data types, meaning that changing a numeric data type will allocate a new object.
In Python 2.X, there are more data types, including int (signed integer), long (long integer [which can also represent octal and hexadecimal]), float (floating-point), and complex (complex numbers).
In Python 3.X, the long type has been removed and replaced with int, with the most commonly used types being int or float.
Strings are represented by the string type and consist of a sequence of characters that can include numbers, letters, and underscores.
In Python, strings are enclosed in quotes, which can be: single quotes (‘ ‘), double quotes (” “), or triple quotes (”’ ”’), and there are two indexing methods:
Left to right indexing starts at 0, with the maximum value being the length of the string minus 1.
Right to left indexing starts at -1, with the maximum value at the beginning of the string.

Indexing is represented with [ ], for example, if we define str=RUNOOB, to get the N value, the expression would be: str[2] or str[-4].
For string operations, there are the following methods:
print(str ) # Outputs the complete string
print(str[0]) # Outputs the first character in the string
print(str[2:5]) # Outputs the substring from the third to the sixth character
print(str[2:]) # Outputs the substring starting from the third character
print(str*2) # Outputs the string twice
print(str+“TEST“) # Outputs the concatenated string
Lists are represented by [ ], and are one of the most frequently used data types in Python, as well as the most general collection data type.
In addition to indexing, slicing operations can also be performed:

list = [ ‘runoob‘, 786 , 2.23, ‘john‘, 70.2 ]
print(list) # Outputs the complete list
print(list[0]) # Outputs the first element of the list
print(list[1:3]) # Outputs the second to third elements
print(list[2:]) # Outputs all elements from the third to the end of the list
print(tinylist*2) # Outputs the list twice
print(list+tinylist) # Prints the combined list
Tuples are similar to lists, but unlike lists, tuples are represented by ( ) and their elements are separated by commas. Tuples cannot be modified, only read. To delete, the entire tuple must be deleted, and operations are not as flexible as lists.
tuple = ( ‘runoob‘, 786 , 2.23, ‘john‘, 70.2 )
tinytuple = (123, ‘john‘)
print(tuple) # Outputs the complete tuple
print(tuple[0]) # Outputs the first element of the tuple
print(tuple[1:3]) # Outputs the second to fourth (not including) elements
print(tuple[2:]) # Outputs all elements from the third to the end of the tuple
print(tinytuple*2) # Outputs the tuple twice
print(tuple+tinytuple) # Prints the combined tuple
Dictionaries are the most flexible data type in Python, aside from lists. The difference between dictionaries and lists is that elements in a dictionary are accessed by keys, not by offsets. Dictionaries are represented by { }, with each element consisting of a key and a value. Keys cannot be duplicated, while values can be duplicated.
dict[‘one‘] = “This is one“
tinydict = {‘name‘: ‘john‘,‘code‘:6734, ‘dept‘: ‘sales‘}
print(dict[‘one‘]) # Outputs the value with key ‘one’
print(dict[2]) # Outputs the value with key 2
print(tinydict) # Outputs the complete dictionary
print(tinydict.keys()) # Outputs all keys
print(tinydict.values()) # Outputs all values
This concludes the introduction to the standard data types in Python.
Additionally, here are some differences between Python 2.X and Python 3.X:
The print function in Python 2 becomes the print() function in Python 3, with an added parentheses.
In Python 2, there is an ASCII str() type, while unicode() is separate and not a byte type.
In Python 3, there are Unicode (utf-8) strings, and utf-8 encoding is used by default in Python 3.x.
Thus, in Python 3, the following syntax is also correct:
These are a few common differences between Python 2 and Python 3; there are certainly other differences, but they will not be discussed here.
Exclusive for fans
I have organized resources worth over 2000+
100G of resources

The content includes:
Planning a software testing learning path from 0 to 1
Common testing templates and strategies in the workplace
Software testing improvement e-books
Classic interview questions
Recorded courses from Songqin
Limited time free~~~
Long press the image below
Add Teacher Tang from Songqin to get free 100G resources

Currently, over 100,000 people have followed and joined us


Long press the QR code
Follow the 【Songqin Online Course】 video account




