# 01-第一节课-变量「刘奕彤」

AI悦创原创
• web 1v1
• web 1v1

## # 2. 新建 Python 代码

• 20221124：日期（2022年11月24日）
• 01：今天上课创建的第几个文件。

## # 3. 初探 print() 函数

``````print("静夜思")
print("床前明月光，疑是地上霜。")
print("举头望明月，低头思故乡。")

print("jing ye shi")
print("chuang qian ming yue guang，yi shi di shang shuang。")
print("ju tou wang ming yue，di tou si gu xiang。")
``````

## # 4. 变量「Variable」

• 变：变化
• 量：有大小的

### # 4.2 从生活中来理解变量

ps：信封在当前空间中，开辟了一个空间叫做：信封，来装东西；冰箱也是如此。

### # 4.3 变量的特点「覆盖」

``````var = 98
var = 95
var = 78
print(var)
``````

``````78
``````
``````var = 98
print(var)
var = 95
print(var)
var = 78
print(var)
``````

``````98
95
78
``````
``````var = 98
print(var)
var = 95
print(var)
var = 78
print(var)
b = var + 10  # 78 + 10
print(b)
``````

``````98
95
78
``````

## # 6. 作业输出三角形

``````    *
*****
*********
``````

## # 7. 变量的赋值过程「2022年11月30日」

``````x = 1
x = x + 10
print(x)  # 11

name1 = "Hugo"
name2 = name1
print(name2)  # Hugo

name1 = "aiyc"
name1 = "Hugo"
print(name1)  # Hugo
``````

``````11
Hugo
Hugo
``````

## # 8. 进阶赋值的方法

### # 8.1 普通赋值方法

``````a = 1
b = 1
c = 1
print(a)
print(b)
print(c)
``````

``````1
1
1
``````

### # 8.2 并排输出

``````a = 1
b = 1
c = 1
# print(a)
# print(b)
# print(c)
print(a, b, c)  # 并排输出，默认空格间隔
``````

``````1 1 1
``````

### # 8.3 多个变量赋值相同的值

``````a = b = c = 1
print(a, b, c)  # 并排输出，默认空格间隔
``````

``````1 1 1
``````

### # 8.4 同时给多个变量赋予不同的值

``````a, b, c = 1, 2, 3
print(a, b, c)  # 并排输出，默认空格间隔
``````

``````1 2 3
``````

## # 9. 变量的命名规则

### # 9.1 区分大小写

``````a = 10
A = 1
print(a)
``````

``````10
``````

### # 9.2 数字不能开头

``````1a = 10
print(a)
``````

``````  File "/Users/huangjiabao/GitHub/SourceCode/MacBookPro16-Code/PythonPCCoder/第二节课/2022113001.py", line 1
1a = 10
^
SyntaxError: invalid syntax
``````

``````a112121 = 10

print(a112121)
``````

``````10
``````

### # 9.3 变量名，不能有空格

``````# 用户名称
user_name = "hugo"  # 变量名不能有空格
print(user_name)
``````

``````hugo
``````

### # 9.4 关键词不能做变量名

``````help("keywords")
``````

``````Here is a list of the Python keywords.  Enter any keyword to get more help.

False               break               for                 not
None                class               from                or
True                continue            global              pass
__peg_parser__      def                 if                  raise
and                 del                 import              return
as                  elif                in                  try
assert              else                is                  while
async               except              lambda              with
await               finally             nonlocal            yield
``````

### # 9.5 不要使用 Python 的内置函数名称做变量名

``````print = "Hugo"
print(print)
``````

``````Traceback (most recent call last):
File "/Users/huangjiabao/GitHub/SourceCode/MacBookPro16-Code/PythonPCCoder/第二节课/2022113001.py", line 2, in <module>
print(print)
TypeError: 'str' object is not callable
``````

## # 注意点⚠️

1. 括号必须是英文括号

1. 必须是英文双引号

2. 变量创建当中是下划线，不是减号

AI悦创·编程一对一

AI悦创·推出辅导班啦，包括「Python 语言辅导班、C++ 辅导班、java 辅导班、算法/数据结构辅导班、少儿编程、pygame 游戏开发、Web、Linux」，全部都是一对一教学：一对一辅导 + 一对一答疑 + 布置作业 + 项目实践等。当然，还有线下线上摄影课程、Photoshop、Premiere 一对一教学、QQ、微信在线，随时响应！微信：Jiabcdefh

C++ 信息奥赛题解，长期更新！长期招收一对一中小学信息奥赛集训，莆田、厦门地区有机会线下上门，其他地区线上。微信：Jiabcdefh

• 0
• 0
• 0
• 0
• 0
• 0

• 按正序
• 按倒序
• 按热度