標籤:numbers -- finally turn 運算式 tuple rom 資料 字串
字串賦值引用特性
同一個字串賦值給不同的變數,所有變數都是同一個對象
>> s = "abc"
>> s1 = "abc"
>> id(s)
34707248
>> id(s1)
34707248
>> id("abc")
34707248
>> s is s1
True
變數賦值
>> a = b = c = 3
>> a,b,c
(3, 3, 3)
>> a,b,c = 1,2,3
>> a,b,c
(1, 2, 3)
變數特性
變數可以重新賦值,變數儲存的是值的引用,即值在記憶體中的地址,當變數被重新賦值後變數指向的地址就會變;會指向一個新的對象;
>> a = 5
>> id(a)
499805328
>> id(5)
499805328
>> a = 1000
>> id(a)
34452592
交換兩個變數的值
>> a,b = b,a
其他語言:
>> a,b = 1,2
>> temp = a
>> a = b
>> b = temp
>> a,b
(2, 1)
查看保留字,關鍵字模組keyword
>> import keyword
>> print(keyword.kwlist)
[‘False‘, ‘None‘, ‘True‘, ‘and‘, ‘as‘, ‘assert‘, ‘break‘, ‘class‘, ‘continue‘, ‘def‘, ‘del‘, ‘elif‘,
‘else‘, ‘except‘, ‘finally‘, ‘for‘, ‘from‘, ‘global‘, ‘if‘, ‘import‘, ‘in‘, ‘is‘, ‘lambda‘, ‘nonloc
al‘, ‘not‘, ‘or‘, ‘pass‘, ‘raise‘, ‘return‘, ‘try‘, ‘while‘, ‘with‘, ‘yield‘]
>> keyword.iskeyword("yield")
True
一行寫多個運算式,”;”
>> a = 1;b = 2;c = 3
代碼換行
>> a = 3\
... +3
>> a
判斷字元類型
>> isinstance(s,str)
True
>> isinstance(s,(str,bytes))
True
help 和 dir 命令
help可以查看對象的使用方法
dir 可以查看模組或對象包含的屬性和方法
python3中的資料類型
Numbers 數字 ,python3中沒有long
--int
--float
--complex
str 字串
list 列表
tuple 元組
dict 字典
set 集合
注釋
單行注釋用#
多行注釋用三引號”” ”””
Python3學習(2)