One of the most suitable languages for introductory programming-Python
The characteristics of the Python language are briefly summarized as follows:
(1) Simple syntax, easy to learn and use
(2) Object-oriented programming
(3) Cross-platform, with portability
(4) Modular development, rich functions
(5) Good extension sex
but the main reason for the fire it up, or its application range is so wide a!
If you learn Python, you can freely choose positions like: artificial intelligence engineer, data analyst, crawler engineer, front-end and back-end development, big data engineer, operation and maintenance test engineer, etc.
Life is short, I use Python, and then I will talk about various basic knowledge points of Python.
One, variables
A variable is a syntax element for storing and representing data values. The value of the variable can be modified by assignment ("=").
Python has its own naming rules : use uppercase letters, lowercase letters, numbers, underscores, Chinese characters and other characters to name.
Note: (1) The first character cannot be a number;
(2) Identifiers cannot appear spaces;
(3) Identifiers cannot be the same as Python keywords;
(4) Case sensitive;
keywords:
Two, operators and expressions
1. Arithmetic operator
2. Assignment operator
3. Comparison operator
4. Logical operator
Simple notation:
and "and": if two are true, then true, otherwise false
or "or": two false is false
not "not" ": negation
5, member operator
6, identity operator
Three, string
Strings are the most commonly used data type in Python. We can use quotes ('or ") to create string
string operators
Escape character
Four, list
A list is an ordered collection that can contain any object. The operations that can be performed include indexing, slicing, adding, multiplying, and checking members. To create a list, simply enclose the different data items separated by commas in square brackets.
List operation
1, add elements
2. Delete element
(1) The pop() method is used to remove an element from the list (the last element by default) and return the value of the element.
(2) Use the del statement to delete the list element at any position, provided that the index is known
(3) Remove the element according to the value
Quintuple
Python tuples are similar to lists, except that the elements of tuples cannot be modified .
Use parentheses for tuples and square brackets for lists.
Tuple creation is very simple, just add elements in parentheses and separate them with commas.
Index range
Six, function
A function is a statement block with a specific function, encapsulated, and reusable.
1. The function code block starts with the def keyword, followed by the function identifier name and parentheses ().
2. Parameters
Formal parameters: local variables in the function, used to receive external data
Actual parameters: external data, used to assign values to the formal parameters
3. Return value
Copy the data inside the function to the outside of the function
4. Variable scope
refers to the scope of the function of the variable
(1) Local variable: The variable defined in the function can only be used inside the function.
(2) Global variables: outside the function, the entire program can be called.
5. Parameter type
(1) Positional parameter
assignment of actual parameters is passed in the order defined by the formal parameters
(2) named passing parameters
when executing a function, you can assign values out of the order defined by the formal parameters
(3) default passing parameters
to the parameters Set default
(4) Variable length parameter passing
Add * in front of the parameter name, the formal parameter will put all the received parameters in a tuple
(5) You can name the parameter
**formal parameter by side length , use the dictionary type to receive all the parameters {"formal parameter": actual parameter}
5. Anonymous function:
the function without a function name when lambda is defined, generally used for higher-order functions Pass parameter
*expression: *lambda parameter: return value expression
Seven, dictionaries and collections
A dictionary is an unordered collection of key-value pairs. The key can be any immutable object, such as numbers, strings, tuples, etc., and the value can be of any type, such as numbers, strings, or even a function.
Each key-value key=>value pair of the dictionary is separated by a colon:, and each key-value pair is separated by a comma, and the entire dictionary is enclosed in curly braces {}
(1) Visit
(2) Increase
(3) Delete
Collection :
A data structure based on a dictionary. A dictionary
containing only keys. The
values are not repeated and can only be immutable data types.
Use the add() method to add items to the set
To delete items in the collection, use the remove() or discard() method.
Use the pop() method to delete the last item