Basic syntax of Python

Basic syntax of Python

"Life is short, I use Python", today we will learn the basic syntax of Python. Mainly include the following knowledge points:

1、 Data types and variables

2、 Naming rules

3、 Input and output

4、 Operator

type of data

1、 Number type (Number)

Python3 Number supports int, float, bool, complex. For students who are new to programming, I will give you an example to facilitate understanding of data types. For example, during Double 11, as an e-commerce operation platform, an order information form will be issued.

The quantity is the int type, and the unit price can have a decimal point is the floating point type. Whether to pay is only true (True) or false (False). Belongs to bool type. Complex is rarely used in normal work, mainly to solve math-related problems, and can be ignored for the time being.

2、 String

Strings are enclosed by **single quotes or double quotes ** in English.

E.g:

'Life is short, I use Python'

'The quality of this product is quite good, and the express delivery is awesome'

"Me and my hometown"

The information commented on major platforms can be represented by strings.

3、 List

The list can store a set of data, encapsulated by a pair of square brackets [] in English.

For example: the content of a record in the order information table above is a list.

[20201101 ,'Notebook', 8000, 1, True]

A list can store a group of data together to form a record. The scenes used in daily life are very frequent.

Through the use of the above common types of numbers, strings, and lists, most of the content in the work can be solved. The key is to choose different usage scenarios according to different data types.

variable

As the name implies, a variable is an amount that can be changed during the running of the program.

For example: 1 million sales today, 1.2 million tomorrow. We need to use variables to express.

sales = 100

sales = 120

The sales means variable. Determine the value and data type of sales based on the data on the right side of "=".

sales = 100, which means that 100 is assigned to the variable sales, and sales is the name of the variable.

Product names can also be represented by variables.

E.g:

Whether the product was successfully purchased

Naming rules

Variables are equivalent to giving each data of different data types a name for later use. So variable naming is also standardized. Everyone needs to be clear.

  1. Identifiers can be composed of letters, numbers, and underline (_), where numbers cannot start.

  2. Identifiers cannot be Python keywords, but they can contain keywords.

  3. The identifier cannot contain spaces.

  4. Strictly case sensitive

The keywords of Python are as follows:

Input and output

The output in Python uses the print() function.

E.g:

These are the basic usage methods of print(). I believe everyone has a preliminary understanding of print. We will explain in detail later.

Input in Python uses the input() function

E.g:

The input function and the output function correspond to the use. This is mainly to have a preliminary understanding of the input and output, and we will think about it later.

Operator

Operators in Python include arithmetic operators, relational operators, logical operators, and assignment operators. This time we first learn arithmetic operators. Including addition, subtraction, multiplication, division, remainder, etc. The same as the symbols in mathematics.

E.g:

I believe that everyone has learned the use of arithmetic operators through the above examples, and will continue to explain the related content of operators later.

Recommended Posts

Basic syntax of Python
Python basic syntax (1)
Python3 basic syntax
Python basic syntax generator
Basic knowledge of Python (1)
Python basic syntax iteration
Python basic syntax and number types
7 features of Python3.9
Python basic summary
Python basic operators
Basic analysis of Python turtle library implementation
The difference between the syntax of java and python
Python basic drawing tutorial (1)
Python function basic learning
python_ crawler basic learning
Python basic data types
Prettytable module of python
Python basic data types
09. Common modules of Python3
Consolidate the foundation of Python (4)
Consolidate the foundation of Python(7)
In-depth understanding of python list (LIST)
Subscripts of tuples in Python
Python basic knowledge question bank
Consolidate the foundation of Python(6)
Analysis of JS of Python crawler
Consolidate the foundation of Python(5)
Python implementation of gomoku program
Analysis of Python Sandbox Escape
Some new features of Python 3.10
Deep understanding of Python multithreading
Python basic drawing tutorial (two)
Analysis of Python object-oriented programming
Python version of OpenCV installation
9 feature engineering techniques of Python
matplotlib of python drawing module
Python method of parameter passing
Consolidate the foundation of Python (3)
Collection of Python Common Modules
The usage of wheel in python
Summary of logarithm method in Python
Python introductory notes [basic grammar (on)]
Use of Pandas in Python development
Detailed implementation of Python plug-in mechanism
Detailed explanation of python sequence types
Implementation of reverse traversal of python list
Python implementation of IOU calculation case
Magic methods and uses of Python
In-depth understanding of Python variable scope
Python preliminary implementation of word2vec operation
Python entry notes [basic grammar (below)]
Python handles the 4 wheels of Chinese
Python calculation of information entropy example
Python file operation basic process analysis
Python crawler basic knowledge points finishing
Implementation of python selenium operation cookie
Use of numpy in Python development
Python simulation of the landlord deal
What is the use of Python
Scrapy simulation login of Python crawler
Analysis of Python conditional control statements