当前位置:网站首页>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 .
边栏推荐
- 1018 public bike Management (30 points)
- Why do high precision CNC machining centers have errors? You should pay attention to these four reasons!
- 1025 pat ranking (25 points)
- How many questions can you answer for the interview of Mechanical Engineer?
- Rte2021 review of the practice and the way of AI OPS landing
- Summary of system stability construction practice
- Rte2021 review HDR technology product practice and exploration
- [matlab] 3D drawing summary
- L - Jungle roads (minimum spanning tree)
- 高精度CNC加工中心为什么会出现误差?这4个原因你要注意!
猜你喜欢

Review 2021, embrace change and live up to Shaohua

The sound network has fully opened the real-time transmission network sd-rtn, which has been free of network wide accidents for seven years - this is FPA!

Svn password forgetting solution

Rte2021 review of the practice and the way of AI OPS landing

Matlab construction operation example

CCF access control system (Full Score code + problem solving idea) 201412-1
![001 data type [basic]](/img/36/90fdf51a20f8c708b9c38610b377d6.jpg)
001 data type [basic]

Four solutions to cross domain problems
![[matlab] 3D drawing summary](/img/57/05156340ccdd79b866c4df955b3713.jpg)
[matlab] 3D drawing summary

Teach you a learning method to quickly master knowledge
随机推荐
1131: genetic correlation
Examples of bubble sorting and matrix element screening in MATLAB
E - highways (minimum spanning tree)
Voice codec based on machine learning Agora silver: support high quality voice interaction at ultra-low bit rate
Why do high precision CNC machining centers have errors? You should pay attention to these four reasons!
Matlab finds prime numbers within 100
A little idea about big experiment data
Npumcm selection question 3 and acmc2020a
Some reference routines for cache update
1133: output family and friends string
Bucket sorting (C language)
分布式--OpenResty+lua+Redis
H - Arctic network (minimum spanning tree)
Bye civil engineering, hello CS, can you change the certificate to the Blue Bridge Cup
1015 reversible primes (20 points)
1151 LCA in a binary tree (30 points)
CCF date calculation (Full Score code + skill summary) February 2, 2015
Matlab two-dimensional array example (extract data)
The short video and live broadcast incubation training camp with goods opens nationwide enrollment!
Complement (Niuke)