“Python/gloss python creating variables”的版本间差异

来自菜鸟教程
跳转至:导航、​搜索
(Pywikibot 4.4.0.dev0)
 
(机器人:添加分类Python基础教程
 
第66行: 第66行:
 
</div>
 
</div>
 
<br />
 
<br />
 +
 +
[[分类:Python基础教程]]

2020年10月29日 (四) 08:48的最新版本

<languages />

Python创建变量

创建变量

变量是用于存储数据值的容器。

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

变量是在您首次为其分配值时创建的。

x = 5

y = "John"

print(x)

print(y)

变量不需要用任何特定类型声明,甚至可以在设置变量后更改类型。

x = 4 # x is of type int

x = "Sally" # x is now of type str

print(x)

可以使用单引号或双引号声明字符串变量:

x = "John"
# is the same as
x = 
  'John'