%s --- 佔字符串的位置python
%d ---佔整型的位置編碼
%% ---轉義(把佔位符轉化成普通的%號)code
只有小寫的s/d才能夠,大寫的S/D不會被識別utf-8
在雙引號以內再用引號要用不一樣的引號,否則內外的引號會出現混淆,通常用單引號ci
msg =unicode
"""
------------------- info ----------------------
name: %s
age: %s
sex : %s
job: %s
hobby: %s
------------------- end ------------------------
"""字符串
print(mag%('alex','20','nan','it','cnb'))string
`name ``=` `'world'``myname ``=` `'python_cat'``words ``=` `f``'Hello {name}. My name is {myname}.'``print``(words)``>>> Hello world. My name ``is` `python_cat.`
f-string方式出自PEP 498(Literal String Interpolation,字面字符串插值),從Python3.6版本引入。其特色是在字符串前加 f 標識,字符串中間則用花括號{}包裹其它字符串變量。it
f字符串拼接 ---只能在python的3.6版本以上才能使用io
"\n"是換行
while 條件:('while True :'or'while else :')
當條件爲假的時候就會跳出循環,當條件一直爲真的時候,就會成爲死循環
break 終止當前的循環
continue 跳出本次循環,繼續下次循環.假裝成循環體中的最後一行
因此跳出循環的方式有三種:
利用條件限制跳出循環
break
continue
+-*/,//,%,**
=
"a = a + 1"=="a += 1"
以此類推:
+=,-=,*=,/=
//=,%=,**=
and(與),or(或),not(非)
print(1 and 0)結果是0,其實與平時的邏輯判斷同理,兩邊同時是真的時候才爲真,一邊假就全假,並且後面出現的真的纔是留下來的真,print(1 and 2)結果是2
print(1 or 0)的結果是真,也與平時的邏輯判斷同理,只要有一邊是真就是真,但在兩邊都是假的時候前邊的假纔是真的假,print(False or 0)的結果是假
"真做假時假亦真,假做真時真亦假"
運算優先級() > not > and > or
==, >,<,!=,>=,<=.(等於,大於,小於,不等於,大於等於,小於等於)
成員運算符
in 在
not in 不在
s =dtrfhfhfbser
print('se' in s) >>> True
print('book' not in s) >>> True
英文1個字節
中文2個字節
英文 2個字節
中文 4個字節
英文 1個字節
歐洲 2個字節
亞洲 3個字節
1byte = 8 bit
1024B = 1KB
1024KB = 1MB
1024 MB = 1GB
1024GB = 1TB