- 數(shù)據(jù)類型
- 容器類型
- 強制類型轉(zhuǎn)換
- 標識符
- 變量賦值
數(shù)據(jù)類型 Base Types: integer, float, bollean, string, bytes

數(shù)據(jù)類型
1、整型 int: 123 , 0 , -121
2、浮點型 float: 2.5 , 0.0 , -1.2
3、布爾類型 bool: False True
4、字符串 str: "ab" , "a\nb" , "I'm" "a\tb\tc"
5、字節(jié)類型 bytes: b"toto\xfe\775"
容器類型:list[], tuple(), str bytes(), dict{:}, set()

容器類型
#list數(shù)組
[1,3,5,7,"9"][:2]
[1, 3]
#數(shù)組函數(shù)
list((1,3,5,7,"9"))[:2]
[1, 3]
#tuple元組
(1,2,"3",)[1]
2
#元組函數(shù)
tuple((1,2,"3",))[1]
2
#dict字典
{"apple":1,"pear":2,"orange":3}
{'apple': 1, 'pear': 2, 'orange': 3}
#字典函數(shù)
dict(apple=1,pear=2,orange=3)
{'apple': 1, 'pear': 2, 'orange': 3}
#set集
{"a","b",1,2}
{1, 2, 'a', 'b'}
#集函數(shù)
set({"a","b",1,2})
{1, 2, 'a', 'b'}
強制類型轉(zhuǎn)換 Conversions

強制類型轉(zhuǎn)換
int("123")
123
#二進制轉(zhuǎn)換成十進制
int("0101",2)
5
#六進制轉(zhuǎn)換成十進制
int("12",16)
18
int(12.3)
12
float("12345")
12345.0
round(12.345,1)
12.3
#bool(x):
#False for null x, empty container x, None or False x;
#True for other x
bool(0)
False
bool(None)
False
bool([])
False
str("abc")
'abc'
#code ? char
chr(35)
'#'
ord("@")
64
ord("%")
37
repr("one")
"'one'"
bytes([72,9,64])
b'H\t@'
list("abcde")
['a', 'b', 'c', 'd', 'e']
list((1,2,3,4,5))
[1, 2, 3, 4, 5]
dict([("apple",1),("pear",2)])
{'apple': 1, 'pear': 2}
dict(apple=1,pear=2)
{'apple': 1, 'pear': 2}
set(["apple","pear"])
{'apple', 'pear'}
#separator str and sequence of str → assembled str
"@".join(["name","net.com"])
'name@net.com'
#str splitted on whitespaces → list of str
"this is an apple".split()
['this', 'is', 'an', 'apple']
#str splitted on separator str → list of str
"this is an apple".split("a")
['this is ', 'n ', 'pple']
#str splitted on separator str → list of str
[int(x) for x in ('1','2',3,3.3)]
[1, 2, 3, 3]
[int(x) for x in ['1','2',3,3.3]]
[1, 2, 3, 3]
標識符 Identifiers 用作變量,函數(shù),模塊,類......名稱

標識符
標識符必須以字母(大小寫均可)或者" _ "開頭,接下來可以重復0到多次(字母|數(shù)字|" _ ") a…zA…Z_ followed by a…zA…Z_0…9
- diacritics allowed but should be avoided
- 禁止使用關(guān)鍵字(python內(nèi)部已經(jīng)使用了的標識符)(language keywords forbidden)
- 區(qū)分大小寫 (lower/UPPER case discrimination)
- 沒有長度限制
變量賦值 Variables assignment =

變量賦值
#"變量名稱"="賦值"
a=120
a=b=50
x,y,z=12,11,10
x+=3
y/=2
z%=3
n=None
#remove name x
del x
#values swap
y,z=z,y