程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Dry goods | variables in Python

編輯:Python

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 !


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved