大家好,
今天我们要学习Python变量。
a=1 # variable as int b="aravin" # variable as string x=5 # First assign the int value to X x='aravin' # Later assign the str value to X print(x) # o/p aravin, recently assign value to use same variable.
a=100 A='India' # a will not overwrite to A both are diff. print(a) print(A)
var=100 mvar='Hello' print(type(var))
例如:
正确名称:
my_variable_name = "Aravin" #蛇类型
myVariableName = "Aravin" #骆驼类型
MyVariableName = "Aravin" #Pascal 类型
myvarname =“阿拉文”
_myvarname =“阿拉文”
myvar_name = "阿拉文"
myvar21 =“阿拉文”
不正确的名称:
2myVar =“你好”
my-var =“你好”
我的 var =“你好”
a,b,c = 5,"aravin","DB"
a = b = c = "Apple"
myVar = ["var1","var2","var3"] a,b,c = myVar print(myVar) print(b)
例如:
a = "python" def myfunc(): print("Hello " + a) myfunc()
a = "python" def myfunc(): a = "python" print("Hai " + a) myfunc() print("Hello " + a)
def myfunc(): global a a = "python" myfunc() print("Hello " + a)
a = "python" def myfunc(): global a a = "Python" myfunc() print("Hai " + x)
以上是Python:变量的详细内容。更多信息请关注PHP中文网其他相关文章!