◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。
大家好,
今天我们要学习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)
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。