SoFunction
Updated on 2024-11-14

How to understand variables in Python

variant

In Python, storing a piece of data requires defining a variable

number1 = 1 #numbe1 is a variable to hold the data: 1

number2 = 2 #number2 is also a variable to hold data: 2

sum = number1+number2 #sum is also a variable that holds the value of 1+2.

Description:

By variable: a quantity that can be changed.

Programs are for processing data, and variables are for storing data

Variables in python don't need to specify their type, the system automatically recognizes it

Content Extension:

variable naming

1. Begin with an underscore or upper- or lower-case letter, which can be followed by any combination of underscores, upper- and lower-case letters and numbers (however, generally beginning with an underscore has a special meaning and is not recommended)

2, it is recommended to use a fixed meaning of the English single word or abbreviation, such as srv = server, skt = socket, generally to posix naming rules-based

3, the recommended hump writing method: a large hump used to write the class, such as MyFirstLove, a small hump such as myFirstLove or posix used to write the variable or function name, the two compared to the current recommended posix writing method, such as: my_first_love

4, avoid reserved words and keywords, such as class, def, break, for; (print out all the keywords of the system method, import keyword;//first cause the keyword module print()//print)

To this article on how to understand Python variables in the article is introduced to this, more related to Python variables in the meaning of the content please search for my previous articles or continue to browse the following related articles I hope that you will support me more in the future!