Variables are containers for storing data values.
Python has no command for declaring a variable.
A variable is created the moment you first assign a value to it.
Variables do not need to be declared with any particular type, and can even change type after they have been set.
If you want to specify the data type of a variable, this can be done with casting.
x = str(3) # x will be '3'
y = int(3) # y will be 3
z = float(3) # z will be 3.0
Try it Yourself »
You can get the data type of a variable with the type()
function.
String variables can be declared either by using single or double quotes:
Variable names are case-sensitive.
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!