大家好,
今天我們要來學習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中文網其他相關文章!