Day1_Python基础_6.变量/字符编码

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Day1_Python基础_6.变量/字符编码相关的知识,希望对你有一定的参考价值。

六、变量\字符编码  

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.

声明变量

1
2
3
#_*_coding:utf-8_*_
 
name = "Alex Li"

上述代码声明了一个变量,变量名为: name,变量name的值为:"Alex Li" 

变量定义的规则:

    • 变量名只能是 字母、数字或下划线的任意组合
    • 变量名的第一个字符不能是数字
    • 以下关键字不能声明为变量名
      [‘and‘, ‘as‘, ‘assert‘, ‘break‘, ‘class‘, ‘continue‘, ‘def‘, ‘del‘, ‘elif‘, ‘else‘, ‘except‘, ‘exec‘, ‘finally‘, ‘for‘, ‘from‘, ‘global‘, ‘if‘, ‘import‘, ‘in‘, ‘is‘, ‘lambda‘, ‘not‘, ‘or‘, ‘pass‘, ‘print‘, ‘raise‘, ‘return‘, ‘try‘, ‘while‘, ‘with‘, ‘yield‘]

变量的赋值

1
2
3
4
5
6
7
8
name = "Alex Li"
 
name2 = name
print(name,name2)
 
name = "Jack"
 
print("What is the value of name2 now?")

以上是关于Day1_Python基础_6.变量/字符编码的主要内容,如果未能解决你的问题,请参考以下文章

Day1_Python基础_4.Python安装

Day1_Python基础_15.while loop

Day1_Python基础_17.拾遗

Day1_Python基础_14.表达式for loop

Day1_Python基础_5.Hello World 程序

Day1_Python基础_3.Python2 or 3 ?