Python第一節
阿新 • • 發佈:2019-03-09
string match list exc ise none all mar 大括號
1、查看python保留字
>>> import keyword >>> 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‘, ‘nonlocal‘, ‘not‘, ‘or‘, ‘pass‘, ‘raise‘, ‘return‘, ‘try‘, ‘while‘, ‘with‘, ‘yield‘]
2、python中註釋
(1)單行註釋以 # 開
(2)多行註釋可以用多個 # 號,還有 ‘‘‘ 和 """:
3、行與縮進
python最具特色的就是使用縮進來表示代碼塊,不需要使用大括號 {} 。
縮進的空格數是可變的,但是同一個代碼塊的語句必須包含相同的縮進空格數
縮進不一致報:IndentationError: unindent does not match any outer indentation level
4、多行語句
Python 通常是一行寫完一條語句,但如果語句很長,我們可以使用反斜杠(\)來實現多行語句
total = item_one + item_two + item_three
在 [], {}, 或 () 中的多行語句,不需要使用反斜杠(\)
total = [‘item_one‘, ‘item_two‘, ‘item_three‘, ‘item_four‘, ‘item_five‘]
5、數字(Number)類型
python中數字有四種類型:整數、布爾型、浮點數和復數。
- int (整數), 如 1, 只有一種整數類型 int,表示為長整型,沒有 python2 中的 Long。
- bool (布爾), 如 True。
- float (浮點數), 如 1.23、3E-2
- complex (復數), 如 1 + 2j、 1.1 + 2.2j
6、字符串(String)類型
- python中單引號和雙引號使用完全相同。
- 使用三引號(‘‘‘或""")可以指定一個多行字符串。
Python第一節