Board logo

标题: Python 变量 [打印本页]

作者: vicky.yu    时间: 2021-3-12 15:52     标题: Python 变量

创建变量
变量是存放数据值的容器。

与其他编程语言不同,Python 没有声明变量的命令。

首次为其赋值时,才会创建变量。

实例
x = 10
y = "Bill"
print(x)
print(y)
运行实例
变量不需要使用任何特定类型声明,甚至可以在设置后更改其类型。

实例
x = 5 # x is of type int
x = "Steve" # x is now of type str
print(x)
运行实例
字符串变量可以使用单引号或双引号进行声明:

实例
x = "Bill"
# is the same as




欢迎光临 赛捷软件论坛 (http://www.sagesoft.cn/bbs/) Powered by Discuz! 7.2