Use docker to open a new machine as an experimental environment
docker run -it centos /bin/bash
yum -y install python3
Edit the first python file
vi hello.py
print('hello world'):wq #Save and exit
python3 hello.py #Run hello.py
There are six standard data types in Python 3:
Python 3 supports int, float, bool, complex (plural).
The string str in Python is enclosed in single quotes ('') or double quotes (" "), and special characters are escaped with backslashes ().
If you don't want to escape the backslash, you can add an r in front of the string to indicate the original string:
In addition, the backslash can be used as a line continuation character, indicating that the next line is a continuation of the previous line. You can also use """...""" or'''...''' to span multiple lines.
Strings can be concatenated using the + operator string, or repeated using the * operator:
There are two indexing methods for strings in Python. The first is from left to right, increasing from 0 in order; the second is from right to left, decreasing in order from -1.
Note that there is no separate character type, a character is a string of length 1.
You can also slice a string to obtain a substring. Separate the two indexes with a colon in the form of a variable [head subscript: tail subscript].
The intercepted range is closed before opening, and both indexes can be omitted:
List (list) is the most frequently used data type in Python.
The list is a list of elements written between square brackets and separated by commas. The types of elements in the list can be different:
Like strings, lists can also be indexed and sliced. After the list is sliced, a new list containing the required elements is returned. I won’t go into details here.
Lists also support concatenation operations, using the + operator:
List has many built-in methods, such as append(), pop(), etc., which will be discussed later.
note:
Tuples are similar to lists, except that the elements of tuples cannot be modified. Tuples are written in parentheses, and the elements are separated by commas.
The element types in the tuple can also be different:
String, list and tuple all belong to sequence (sequence).
note:
A set is a set of unordered and non-repeating elements.
The basic function is to conduct membership testing and eliminate duplicate elements.
You can use braces or set() to create a set collection. Note: To create an empty collection, you must use set() instead of {}, because {} is used to create an empty dictionary.
Dictionary (dictionary) is another very useful built-in data type in Python.
A dictionary is a mapping type, which is an unordered collection of key:value pairs.
Keywords must use immutable types, which means that lists and tuples containing mutable types cannot be keywords.
In the same dictionary, the keywords must also be different from each other.
The dictionary type also has some built-in functions, such as clear(), keys(), values(), etc.
note:
Recommended Posts