Home  >  Article  >  Backend Development  >  How to use variables in Python_How to use variables in Python

How to use variables in Python_How to use variables in Python

WBOY
WBOYforward
2024-04-02 14:16:01558browse

1. First of all, friends who have learned C language know that if you want to use variables in C language, you need to define a type of variable before you can use it.

How to use variables in Python_How to use variables in Python

2. Then in the Python language, there is no need to define it in advance, you can just assign it directly where it is used.

How to use variables in Python_How to use variables in Python

3. The Python compiler will automatically assign a data type based on the data to which the variable is assigned.

4. Global variables defined in C language need to be outside the function.

How to use variables in Python_How to use variables in Python

5. Then Python can also define global variables, which need to be declared outside the function.

How to use variables in Python_How to use variables in Python

6. When using external global variables in a function in C language, you can use them directly without declaring them.

How to use variables in Python_How to use variables in Python

7. Finally, when using python global variables, they need to be declared with global in the function, otherwise they will be considered new local variables.

How to use variables in Python_How to use variables in Python

The above is the detailed content of How to use variables in Python_How to use variables in Python. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:zol.com.cn. If there is any infringement, please contact admin@php.cn delete