標籤:break word 模組 多行注釋 oba 標準 字串 預設 字典
預設情況下,python以UTF-8編碼,所有的字串都是Unicode字串,可以為代碼定義不同的的編碼。
#coding:UTF-8#OR#-*- coding:UTF-8 -*-
保留字及為關鍵字,不能作為任何標識符名稱。查看目前的版本所有關鍵字:keyword模組
1 import keyword #匯入keyword模組2 keyword.kwlist
[‘False‘, ‘None‘, ‘True‘, ‘and‘, ‘as‘, ‘assert‘, ‘break‘, ‘class‘, ‘continue‘, ‘def‘, ‘del‘, ‘elif‘, ‘else‘, ‘except‘, ‘finally‘, ‘for‘, ‘from‘, ‘global‘, ‘if‘, ‘import‘, ‘in‘, ‘is‘, ‘la
單行注釋:代碼中以#開頭的行即為注釋,程式在執行時不會執行該行
多行注釋:"""多行注釋""" or ‘‘‘多行注釋‘‘
#這是一個注釋‘‘‘這是第二個注釋‘‘‘"""這是第3個注釋"""
python中有資料類型:布爾型、整型、長整型、浮點型、字串、列表、元組、字典、日期
- 布爾型(bool): True / False,任何數值的0,Null 字元串,空列表[],空元組(),空字典{}都是False,函數或方法傳回值為空白的同為False,其他資料都為True。
In [4]: bool(True)Out[4]: TrueIn [5]: bool(False)Out[5]: FalseIn [6]: bool(0)Out[6]: FalseIn [8]: bool([]) #空列表 Out[8]: FalseIn [9]: bool(()) #空元組Out[9]: FalseIn [10]: bool({}) #空字典Out[10]: FalseIn [12]: bool(1)Out[12]: True.................
- 整數(int):範圍-2**31 到2**31-1,超出這個範圍的為長整型
- 字串(str):被引號括起來的都是字串
#type():查看資料類型In [13]: type("hello world")Out[13]: strIn [14]: type("123")Out[14]: str
標準輸出,print()預設輸出是換行的,如果要實現不換行,需在末尾加上 end=""
>>>print("hello world!",end="","hello python!") #不換行輸出>>>hello world! hello python!
【Python】python基礎文法 編碼