python的基本資料型別:
數值型別:int
,float
,complex
字串::str
布林型別:boll
只有兩個值:true
,false
none型別:
只有乙個值:none
列表型別:list
元組型別:tuple
字典型別:dict
集合型別:set
位元組型別:bytes
算數運算子
+,-
,*,/
,%,//
,**
關係運算子
>
,>=
,<
,<=,==
,!=# 注意字串的比較要使用ascii碼
# a~z: 65~90
# a~z: 97~122
# 0~9: 48~57
print
('a'
>
'b')
# false
print
('abc'
>
'acb'
)# false
邏輯運算子
and,or
,not
# 短路操作
# and: 兩邊都為真則為真,只要有乙個假則為假
s =3
and0
and4
# s = 0
# or: 兩邊都為假則為假,只要有乙個真則為真
s =0or3
or4# s = 3
賦值運算子
# =, +=, -, -=, *=, /=, %=, **=
# s = 10
# s += 1 <=> s = s + 1 # s= 11
成員運算子
in
,not
inprint(1
in[1,
2,3]
)# true
print
('abc'
notin
["abcdefg"])
# true
身份運算子
is,is
not# 比較記憶體位址
a =100
b =100
print(id
(a)==
id(b)
)# true
print
(a is b)
# true
位運算子
&,|
,~,^
,<<
,>>
if 條件會自動轉換成bool進行判斷,如果為真
則進入if,否則不進入
常見bool值:
數值型別:0為假,其他為真
字串型別:""空字串為假,其他為真
none型別:none為假
bool型別:true為真,fals為假
list型別:[
]空列表為假,其他為真
dict型別:空字典為假,其他為真
tuple型別:(
)空元組為假,其他為真
if單分支:if
if
true
:print
('hello'
)
if雙分支:if-else
a =
2if a ==10:
print
("1"
)else
:print
("0"
)
if多分支:if-elif-else
b =
10if b >5:
print
('a>5'
)elif b ==5:
print
('b=5'
)else
:print
('b<5'
)
day 03 python基本資料型別
組合 combination 是乙個數學名詞。一般地,從n個不同的元素中,任取m m n 個元素為一組,叫作從n個不同元素中取出m個元素的乙個組合。序列,序列指的是一塊可存放多個值的連續記憶體空間,這些值按一定順序排列,可通過每個值所在位置的編號 稱為索引 訪問它們。為了更形象的認識序列,可以將它看...
day03 python 編碼初識
1 索引 下標 元素字元中的單個字母 s guan 0123 從左向右 4 3 2 1 從右向左 print s 2 從左向右 print s 3 從又向左 note 超出索引範圍時會報錯 2 切片 print s 起始位置 終止位置 print s 1 4 note name 預設從name開始位...
python學習筆記day03 資料型別
int 用於計算 1,2,3,4,bool 用於使用者判斷 true false str 不可變資料型別 用於儲存少量資料 xuanxuanlovebaby list 可變資料型別 用於儲存大量資料 123,xuanxuan 1.2,true dict 可變資料型別 一般可以用於索引 根據鍵索引值 ...