# 01-Python变量「精卫」

AI悦创原创1v1Python 1v11v1Python 1v1大约 4 分钟...约 1051 字

## 1. 理解变量

• 变量就是在计算机的内存当中开辟空间。——例如信封一样。
• 变量会被覆盖。

• 从上到下
• 从右到左
• 最后一步，才是赋值

## 3. 实操

### 3.1 Code1

``````x = 1
x = x + 10
# 井号是注释，注释就是人看得见，计算机看不见。代码注解，说明。
# print: 打印、输出
print(x)
``````

``````11
``````

### 3.2 Code2

``````name1 = "lilei"
name2 = name1
print(name2)
``````

``````lilei
``````

### 3.3 Code3

``````name1 = "hanmeimei"
name1 = "AI悦创"
print(name1)
``````

``````AI悦创
``````

## 4. 进阶的赋值方法

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

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

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

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

## 5. 练习一下

Austin 想喝果汁，Jaden 想喝可乐哥哥和弟弟都有专属的杯子，不喜欢用对方的杯子。

zh

Suppose you have two children, the elder brother is named Austin, and the younger brother is named Jaden. Austin wants to drink juice, and Jaden wants to drink cola. Both brothers have their own exclusive cups and don't like to use each other's cups. There is only one cup of juice and one cup of cola left at home, and you accidentally filled the elder brother's cup with cola and the younger brother's cup with juice. How can you swap the juice in the brothers' cups?

``````Austin = "Coke"  # 该赋值可以理解为倒果汁的过程
Jaden = "juice"  # 该赋值可以理解为倒果汁的过程
print("Austin", Austin)
print("Jaden", Jaden)
# 待补充代码
print("Austin", Austin)
print("Jaden", Jaden)
``````

``````Austin = "Coke"
Jaden = "juice"
print("Austin", Austin)
print("Jaden", Jaden)
# 待补充代码
print("Austin", Jaden)
print("Jaden", Austin)
``````
``````Austin = "Coke"
Jaden = "juice"
print("Austin", Austin)  # 输出 print(a, b, c) Austin Coke
print("Jaden", Jaden)  # 输出 Jaden juice
empty_cup = Austin
Austin = Jaden
Jaden = empty_cup
print("Austin", Austin)  # 输出 Austin juice
print("Jaden", Jaden)  # 输出 Jaden Coke
``````

## 6. 变量的命名规则

### 6.1 变量是区分大小写的

``````n = "aiyc"
N = "zhaojinwei"
print(n)
``````

``````aiyc
``````

### 6.2 不能使用数字开头

``````n11111u2222m2112121212121 = 19
print(n11111u2222m2112121212121)
``````

``````19
``````

### 6.2 不能空格间隔

``````username = "aiyc"
user_name = "aiyc"
``````

### 6.3 系统关键词不能做变量名

``````as = "aiyc"
# 计算机是要认为你这个 as 是关键词呢、还是变量呢？——显然，计算机不是人，就算是人看到这样的变量也会有疑惑吧。
``````

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

``````As = "aiyc"
aS = "aiyc"
AS = "aiyc"
``````

### 6.4 不要使用内置函数名做变量名

``````print = "zhaojinwei"
print(print)
``````

## 快捷键

• `Command + /`：注释

AI悦创·编程一对一

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

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

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

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