Files
2025PY/day03/06-变量.py
2025-05-22 16:50:44 +08:00

32 lines
869 B
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 变量
# 变量就像盒子,可以存放内容
# 1.变量声明的格式
# 变量的自定义名称 = 值
# 在整个的python文档中通过名称得到值
# 2.变量的意义:
# 解决重复值(多次使用)的问题
# 变量的值是可以改变的
# 约定:程序中使用的值,先声明变量再使用
# a = 200 # 定义变量
# a = 1 # 修改上面变量a的值
# a = 10 # 修改变量的值
# print(a + 1)
# print(a + 2)
# print(a + 3)
# print(a + 4)
# print(a + 5)
# 3.变量声明的组成
# 3.1.约定一个变量的名称(语义化),存储对应的值
name = 'zhangsan'
age = 18
sex = ''
# 3.2.中间的等号(赋值符号)
grade = 'IT231' # 将右边的结果赋值给左边
# 3.3.变量的值变量的值存在于6大数据类型中通过变量名来访问变量对应的值
print(name,age,sex,grade) # zhangsan 18 男 IT221