黑猴子的家:Python 变量

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、声明变量

name = "hei hou zi"

上述代码声明了一个变量,变量名为: name,变量name的值为:"hei hou zi"

2、变量定义的规则

(1)变量名只能是 字母、数字或下划线的任意组合
(2)变量名的第一个字符不能是数字
(3)以下关键字不能声明为变量名
['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']

3、变量的赋值

name = "heihouzidejia"
name2 = name
print(name,name2)
name = "Jack"
print("What is the value of name2 now?")

4、var.py

# Author:黑猴子的家

name = "hei hou zi de jia"

print("My name is ",name)

name2 = name

name = "qitiandasheng"

# name2  是 什么??
print(name,name2)

#驼峰 + 下划线
gf_of_heihouzi = "hei hou zi de jia"
Gf_Of_Heihouzi = "hei hou zi de jia"

你可能感兴趣的:(黑猴子的家:Python 变量)