变量

变量字符编码

Variables are used to store information to be referenced and manipulated in a computer program.They also provide a way of labeling data with a descriptive name.so our programs can be understood more clearly by the reader and ourselves .It is helpful to think of variables as containers that hold information.Their sole purpose is to label and store data in memory.THIS data can then be used throughout your program.

声明变量

#--*--coding:utf-8--*--

name = “Zero”

  上面代码声明了一个变量,变量名为:name,变量name的值为:“Zero”

变量定义的规则

  • 变量名只能是字母、数字或下划线的任意组合
  • 变量名的第一个字符不能是数字
  • 一下关键字不能声明为变量 

 【’and‘、‘as’、‘assert’、‘break’、‘class’、‘continue’、‘def’、‘del’、‘elif’、‘else’、‘except’、‘exec’、‘finally’、‘for’、‘from’、

    ‘global’、‘if’、‘inport’、‘in’、‘is’、‘lambda’、‘not’、‘or’、‘pass’、‘print’、‘raise’、‘return’、‘try’、‘while’、‘yield’】

变量的赋值

name = "Zero"

name2 = name

print ("My name is",name,name2)

name = "One"

print ("What is the value of name2 now?")

ps:变量名需要有含义,能够让人一目了然,如:name、age等具有含义的单词;别使用中文和拼音作为变量名,这样显得不专业,哈哈!当表示一些复查的含义的变量时,可以这样写!

如:gfofoldboy,表示不能这样,应该使用“—”和大写区分开:gf_of_oldboy,GFOfoldboy等,官方建议使用“—”。

常量,如π等在Python里面是没有常量这个概念的!如想定义一个常量需要将变量名大写,如PIE = “Zero”,这是能够更改的,但是这样表示是为了提示这是一个常量,不应该更改它!

原文地址:https://www.cnblogs.com/lzhn/p/7793099.html