My python career

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 ("=").
Insert picture description here

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:
Insert picture description here

Two, operators and expressions

1. Arithmetic operator
Insert picture description here
2. Assignment operator
Insert picture description here
3. Comparison operator
Insert picture description here
4. Logical operator
Insert picture description here
Simple notation:
and "and": if two are true, then true, otherwise false
or "or": two false is false
not "not" ": negation
5, member operator
Insert picture description here
6, identity operator
Insert picture description here

Three, string

Strings are the most commonly used data type in Python. We can use quotes ('or ") to create string
Insert picture description here
string operators
Insert picture description here

Escape character
Insert picture description here

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.
Insert picture description here

List operation
1, add elements
Insert picture description here

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.
Insert picture description here
(2) Use the del statement to delete the list element at any position, provided that the index is known
Insert picture description here
(3) Remove the element according to the value
Insert picture description here

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.

Insert picture description here
Index range
Insert picture description here

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 ().
Insert picture description here

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
Insert picture description here

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
Insert picture description here

(4) Variable length parameter passing
Add * in front of the parameter name, the formal parameter will put all the received parameters in a tuple
Insert picture description here

(5) You can name the parameter
**formal parameter by side length , use the dictionary type to receive all the parameters {"formal parameter": actual parameter}
Insert picture description here
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 {}
Insert picture description here

(1) Visit
Insert picture description here

(2) Increase
Insert picture description here

(3) Delete
Insert picture description here

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
Insert picture description here

To delete items in the collection, use the remove() or discard() method.
Insert picture description here
Use the pop() method to delete the last item
Insert picture description here

Guess you like

Origin blog.csdn.net/Python_Apple/article/details/109397897