当前位置:网站首页>4.3 variables and assignments
4.3 variables and assignments
2022-06-30 15:15:00 【Andy Python learning notes】
4.3 Variables and assignments
4.3.1 Concept of variables
Variable , That is, the amount of change , It can be understood as a container .
This container can hold ( Storage ) All kinds of things ( data ), And things can be changed , There are many containers for storing different data in the computer , To distinguish between different containers , We need to name these containers , That's variable name , We can access variables by their names .
The four cans in the picture below are the four containers , Four variables .
Depending on the food stored , We can name them canned strawberries 、 Canned cherry 、 Canned grapes 、 Canned oranges . In this way, you can get the specific variable through the variable name .

4.3.2 The assignment of a variable
stay Python in , The assigned symbol is =.= It doesn't mean the left is equal to the right , stay Python in = Is the meaning of assignment , It means that = The content on the right is put in = In the container on the left .
Canned strawberries = strawberry
Put strawberries in a can of strawberries .
stay Python in , The equals sign is ==.
4.3.3 Assign a value to a variable
# A variable called name, = It means assignment , Andy is a variable name Stored content
name = ' Andy '
# Check the variable name Stored content
name
' Andy '
【 Andy 】 Is the character , You need quotation marks before and after assigning values to variables .
# A variable called age, = It means assignment ,25 It's a variable. name Stored content
age = 25
# Check the variable age Stored content
age
25
【25】 to age When assigning values, you can use quotation marks to represent the string type , You can do it without quotes , It's an integer .
# Assign a value to a variable
number_1 = 10
number_2 = 10
# print Function to view variables
print(number_1)
print(number_2)
10
10
stay Python Two variables are equal :
number_1 == number_2
4.3.4 Variable naming conventions
1、 Variable names must be alphabetic or underlined _ Start , Don't start with numbers ;
2、 Try to describe the data contained ; If the name is name, Age use age, You can see what variables store at a glance , Convenient to call ;
3、 Do not use what you will learn in the future Python Keywords in ;
4、 Variable names are case sensitive ,name and Name Represents two different variables .
# To the variable age First assignment
age = 25
# To the variable age The second assignment
age = 20
# To the variable age The third assignment
age = 10
# see age
age
10
The above code we give age Assign three times , The final output is the third assignment ;
stay Python in , The final value of the variable is equal to the last assignment of the variable .
4.3.5 summary
1、= It means assigning values to variables ;
2、== It means equal to ;
3、 The final value of the variable is equal to the final assignment .
边栏推荐
- CCF window (Full Score code + problem solving idea) March 2, 2014
- One dimensional and two dimensional array addresses
- CCF image rotation (Full Score code + problem solving idea) 201503-01
- day02
- Scattered knowledge of C language (unfinished)
- 1058 a+b in Hogwarts (20 points)
- A little idea about big experiment data
- Sum of CCF digits (full mark code + problem solving idea) 201512-1
- Voice codec based on machine learning Agora silver: support high quality voice interaction at ultra-low bit rate
- CCF access control system (Full Score code + problem solving idea) 201412-1
猜你喜欢

Review 2021, embrace change and live up to Shaohua
![001 data type [basic]](/img/36/90fdf51a20f8c708b9c38610b377d6.jpg)
001 data type [basic]

Voice codec based on machine learning Agora silver: support high quality voice interaction at ultra-low bit rate

CCF sequence segmentation (Full Score code + problem solving idea) 201509 -1

CCF command line options (Full Score code + problem solving ideas + skill summary) March 3, 2014

Sum of CCF digits (full mark code + problem solving idea) 201512-1

The short video and live broadcast incubation training camp with goods opens nationwide enrollment!

Experiment of the planning group of the West University of technology -- pipeline CPU and data processing Adventure

CCF drawing (full mark code + problem solving ideas + skill summary) February 2, 2014

Four solutions to cross domain problems
随机推荐
1135: paired base chain
Sum of CCF digits (full mark code + problem solving idea) 201512-1
[matlab] 3D drawing summary
J - Borg maze (minimum spanning tree +bfs)
The crystal ball "data insight" was officially launched: insight into the change of consumption trend and the details of interactive experience
CCF access control system (Full Score code + problem solving idea) 201412-1
1134: Legal C identifier query
立式加工中心调试的步骤
001 data type [basic]
Win10 one click Reset win10 to solve all system bugs without deleting any files and Applications
One dimensional and two dimensional array addresses
N - Is There A Second Way Left? (minimum spanning tree, Kruskal)
1149 dangerous goods packaging (25 points)
Noj1042 - electronic mouse running through maze
1030 travel plan (30 points)
K high frequency elements before sorting
H - Arctic network (minimum spanning tree)
Win10 backup backup shows that creating a shared protection point on the shadow failed
1151 LCA in a binary tree (30 points)
Programming exercises: special numbers (problem solving ideas + code implementation)