Follow 👆 the official account and reply "python" to get the zero-based tutorial! Source from the internet, please delete if infringing
1: Introduction:
Python is an interpreted, object-oriented language.
The syntax and dynamic typing of Python, along with its nature as an interpreted language, make it a programming language suitable for scripting and rapid application development on most platforms.
[Tutorial Retrieval method at the end!!]
2: Basic Syntax of Python
2.1. Literal
A literal: A fixed value written in code is called a literal.
Python has 6 common types of values (data).
Note: The type() statement can check the data type stored in a variable.
2.2. Comments
Single-line comment: Starts with #, and all text to the right of # is treated as an explanation, not an actual program to be executed, serving as auxiliary explanation.
Note: It is generally recommended to leave a space between the # sign and the comment content.
Multi-line comment: Enclosed by a pair of triple double quotes.
2.3. Data Type Conversion
2.4. Identifier
An identifier: A series of names used by the user in programming to name variables, classes, methods, etc.
In identifier naming, only the following four types of elements are allowed: English, Chinese, numbers, underscores (_).
Note: It is not recommended to use Chinese, numbers cannot start, and keywords cannot be used.
2.5. Operators
Arithmetic (mathematical) operators:
Compound assignment operators:
2.6. Strings
2.6.1. Three Ways to Define Strings
Single quote definition method: Double quote definition method: Triple quote definition method:
Among them, the single quote definition can contain double quotes; the double quote definition can contain single quotes; and the escape character (\) can be used to neutralize quotes to become ordinary strings.
2.6.2. String Concatenation
*Note: **Strings cannot be concatenated with non-string variables.
The default print statement outputs content automatically wraps. In the print statement, adding end=” can output without wrapping.
2.6.3. String Formatting
We can use the following syntax to complete quick concatenation of strings and variables.
The following code completes the placement of strings, integers, and floating-point numbers, three different types of variables.
Among them, % indicates a placeholder, and when there is no need to use variables for data storage, the expression can be formatted directly (the position of the variable is placed in the expression) to simplify the code.
2.6.4. Control of Formatting Precision
We can use the auxiliary symbol “m.n” to control the width and precision of the data.
m controls the width, which must be a number; if the set width is less than the number itself, it will not take effect.
.n controls the decimal precision, which must be a number and will round the decimal.
Example: %5d: means to control the width of the integer to 5 digits, such as the number 11, it will become: [space][space][space]11, with three spaces to supplement the width.
%5.2f: means to control the width to 5 and set the decimal precision to 2. The decimal point and the decimal part are also included in the width calculation. For example, after setting 11.345 to %7.2f, the result is: [space][space]11.35. 2 spaces supplement the width, and the decimal part is limited to 2 digits of precision, rounded to .35.
%.2f: means no width limit, only sets the decimal precision to 2, such as 11.345 set to %.2f, the result is 11.35.
2.6.5. String Quick Formatting
Using the syntax: f”Content{variable}” for quick formatting.
Note: This writing method does not control precision, does not care about types.
2.7. Data Input
Using input() statement can get input from the keyboard.
Note: No matter what type of data is input from the keyboard, the obtained data is always of string type.
Warm reminder: Due to limited space, a packaged folder has been created, and the retrieval method is at the end.
3: Python Conditional Statements
3.1. Basic Format of if Statements
The code block belonging to the if statement must be indented with 4 spaces.
Python determines the affiliation of code blocks through indentation.
3.2. if elif else Statements
4: Python Loop Statements
4.1. while Loop
4.2. for Loop
4.3. range Statement
Used to obtain a sequence of numbers.
5: Python Functions
A function is an organized, reusable code segment designed to implement specific functionality.
Function definition:
Note: If a function does not use the return statement to return data, it will return the literal None; in if statements, None is equivalent to False; if a variable is defined but does not need a specific value, None can be used as a substitute.
Using the global keyword allows declaring a variable as global within the function.
6: Python Data Containers
A data type that can hold multiple pieces of data, with each piece of data referred to as an element. Each element can be of any type.
Warm reminder: Due to limited space, a packaged folder has been created, and the retrieval method is at the end.
6.1. list (List)
Basic syntax:
List methods:
List characteristics:
6.2. tuple (Tuple)
Basic syntax:
Note: A tuple with only one data must have a comma added after this data.
Tuple methods:
Tuple characteristics:
6.3. str (String)
String methods:
Warm reminder: Due to limited space, a packaged folder has been created, and the retrieval method is at the end.
String characteristics:
The string container can only hold a single type, which is string type.
Strings cannot be modified; if modification is necessary, a new string must be created, and the old string cannot be modified.
6.4. Slicing Sequences
A sequence refers to: content that is continuous, ordered, and can be indexed.
Lists, tuples, and strings can all be considered sequences.
Syntax: sequence[start index:end index:step]
Indicates starting from a specified position in the sequence, taking elements one by one until the specified position ends, resulting in a new sequence.
-
The start index indicates where to start, which can be left empty, interpreted as starting from the beginning.
-
The end index (exclusive) indicates where to end, which can also be left empty, interpreted as slicing to the end.
-
The step indicates the interval of taking elements.
-
The step being a negative number indicates reverse taking (note that the start index and end index must also be marked in reverse).
6.5. set (Set)
Basic syntax:
Set methods:
Set characteristics:
Compared to lists, tuples, and strings, it does not support duplicate elements (it has a built-in deduplication feature) and is unordered.
6.6. dict (Dictionary)
Dictionary Definition
Common operations for dictionaries:
Dictionary characteristics:
-
The Key and Value of the key-value pair can be of any type (Key cannot be a dictionary).
-
Keys in a dictionary cannot be duplicated; repeating an addition is equivalent to overwriting the original data.
-
A dictionary cannot be indexed by subscript; instead, it is accessed by Key to retrieve Value.
6.7. General Operations of Data Containers
Comparison of data container characteristics:
Common functions of containers:
About Python Learning Guide
Learning Python is beneficial for both employment and making money through side jobs, but to learn Python well, one must have a study plan. Finally, I would like to share a complete set of Python learning materials to help those who want to learn Python!
Including: Python activation code + installation package, Python web development, Python crawling, Python data analysis, artificial intelligence, automation office, and other learning tutorials. It will help you systematically learn Python from scratch!
👉 Python All Directions Learning Route 👈
The learning route for all directions of Python is to organize commonly used technical points of Python, forming a summary of knowledge points in various fields. Its usefulness lies in that you can find corresponding learning resources based on the above knowledge points, ensuring that your learning is comprehensive. (Complete tutorial retrieval at the end)
👉 600 Collection of Python Learning Videos 👈
Watching zero-based learning videos is the quickest and most effective way to learn. Following the teacher’s ideas in the videos, from basic to deep, it is still very easy to get started.
Warm reminder: Due to limited space, a packaged folder has been created, and the retrieval method is at the end.
👉 70 Practical Python Cases & Source Code 👈
Theoretical knowledge alone is useless; you must learn to practice hands-on to apply what you have learned in practice. At this point, you can do some practical cases to learn.
👉 Python Big Company Interview Materials 👈
We learn Python to find high-paying jobs; the following interview questions are from leading internet companies like Alibaba, Tencent, and ByteDance with authoritative answers provided by Alibaba experts. After finishing this set of interview materials, I believe everyone will find a satisfactory job.
👉 Python Side Job and Part-time Route & Method 👈
Learning Python is beneficial for both employment and making money through side jobs, but to learn how to take on part-time jobs, one must have a study plan.
-
Like + See Again
-
Reply in the official account: “python”
Retrieve the latest Python zero-based learning materials for 2024,Reply in the backend:Python