Dry goods | variables in Python

Manon rushes forward 2022-06-23 17:43:26 阅读数:321

drygoodsvariablespython

Python What are the variables in ? Variable , Record the changing state of things . It is to make the computer have a certain function of human , It can better complete the tasks assigned by human beings , This gave birth to variables .

" Variables are composed of three parts "

Variable name Assignment symbol A variable's value

name = "Mike"

What is a variable name ?

When variables are defined , It will apply for a space in memory for storing variable values , And the variable name , It is the house number of this space , Can easily find this memory space .

The variable name should be able to describe the meaning of the variable value , It is best to consider the name and the meaning , Proper variable name naming can improve the readability of your program .

  • In order to improve their position in the programmer , Remember not to use Pinyin .
  • In order to improve their position in the programmer , Never use Chinese .
  • Not to be used Python Keywords in .
  • Do not start with a number .

How variable names are named

Variable names are generally Three ways of naming .

  • Pure lowercase + Numbers + Underline . Variable names are usually used in this way .

<!---->

  • Hump body . title case .

<!---->

  • Pure capital . This is usually used to define constants in a program . Be careful , It's a rule of thumb , No Python Its own grammar .

Assignment symbol

above “=” The equal sign is the assignment symbol of the variable . Its meaning is to bind the memory address of the variable value on the right to the variable name on the left , When we use the variable name, we can find the variable value .

A variable's value

The variable value is The state of things , After the definition, you can use the variable name to access . The variable value has a reference number , Once this space has been referenced for 0, That means we have no way to find this space , If not cleaned , Will cause memory to be occupied . Once you can't find this space , It will trigger Python Memory management for : Garbage collection mechanism , Recycle the space . Variables have three very important characteristics :id、type、 A variable's value .

  • id: Is the memory space address of the variable value , Each value has a unique id. Different memory addresses ,id It's different . have access to id() To view the memory address of the variable .
  • type: Different types of values record different states of things , This is it. Python Data type of . have access to type() Check it out. .

A variable's value : Store the value itself .

Example

For example, the average score of a student , We input students' scores in three subjects in turn , Calculate the student's average score and print it out , Keep one decimal point for the average score and calculate the percentage of the student's Chinese score in the total score ?

Today, let's talk about this first !

版权声明:本文为[Manon rushes forward]所创,转载请带上原文链接,感谢。 https://pythonmana.com/2022/01/202201061510024533.html