Catalogue
[TOC]
This article for 刚学
Python's small white, if you feel that the variable has a good grasp, you can watch other articles
Here, let me say a brief summary of my variables:变量是为了存储运算程序中的一些中间结果, 为了方便日后调用
What is
变量
?
Here I give a simple example :
3 * 4 = 12
When we write an arithmetic program, we tend to encounter a lot of *3 4 = 12**
There are two ways to use this program many times.
- One way is to directly 3 * 4 in the Code
- The other is to use a variable to store 3 * 4
Like what:
x = 3y = 4z = x * yprint("z = ", z)
The result of the operation is:
z = 12
If the use of variables, in the program as long as the input z
, you can directly invoke z
, from the strict point of view of the code, the direct use of variables, can be more beautiful code, from a convenient point of view, the use of variables can shorten the time to write code, like z = x * y, only need to invoke the resultsz
A lot of people would say, little, you bastard, write a bunch of things we all know. Come on, I want a refund.
Then I'm here to say that the refund is not back AH.
How to write a good variable?
Let me cite one more example:
x = "CoXieQqun"y = "725479218"z = x + y print(z)
The result of the operation is:
CoXieQqun725479218
I don't know if you can read it, look at the variable and the value of the variable, if you don't look at the value of the variable, such as:
xxx = "CoXieQqun"xxx = "725479218"
Do you know what a variable is?
As you may know, the meaning of the above represents
Let's change the way it says:
What do you know and say without looking at X
Y
it?
So, in naming variables, you need to know what your variables are, what to do, what to name is a good variable, here I sell a xiaoguanzi, see my day Show
letters = "CoXieQqun"Group = "725479218"my = name + number
Do not know to understand no, whether you understand not understand, do it yourself win
+ R
, input cmd
, input in the command line python
(the premise of Python installation success). Do print
it yourself and experience it.
Underline naming method and hump naming method
When writing a program, we tend to write a few words in a variable, such as:
sutudent = "CoXie"number = "01"
In real life, with large amounts of data, it is cumbersome to execute code so that it is time to store two of data in a variable, such as:
studentnumber = "CoXie01"
If you look at this variable name, a lot of people are looking at the face of the crazy, what is this big string of things? In the strict code, generally encountered this situation, the following two kinds of naming methods are used:
underline naming method :
Take the above as an example:
student_number = "CoXie01"
Obviously you can see, student
and number
two words, in the name of the variable can be very clear to know, student_number
the role of students编号
Hump Naming Method :
What is the Hump naming method?
Hump nomenclature, also known as Camel name Law, its name is like a camel, there are peaks, here I do not say anything, a picture, let you understand the hump naming law.
Conclusion
For this series of articles, I will give priority to the publication of my public number:
Python next day: Variable description and variable assignment