Python內建型態的資料型態有以下幾種:
數值型態(Numeric type) - int, long, float, bool, complex
字串型態(String type)
容器型態(Container type) - list, set, dict, tuple
名稱只能由大小寫字母、_底線、中文、數字組成,英文字母大小寫式為不同字元。
第一個字母必須為:大小寫字母、_底線、中文。
變數名稱不能與Python內建的保留字相同,例如:and or not def print ...。
acos and array asin assert atan
break class close continue cos Data def del
e elif else except exec exp fabs float finally floor for from
global if import in input int is lambda log log10 not open or
pass pi print raise range return sin sqrt tan try type while write zeros
Ex: str = "林大明的報告內有'單引號" 或 str = '林大明的報告內有"雙引號'
【資料轉換】
int():轉為整數
str():轉為字串
bool():轉為布林值
float():轉為浮點數
※要轉換的內容不可以是串列list※
若a=10,b=20則:
c=a #c=10,a=10,b=20
a=b #a=20,b=20,c=10
b=c #b=10,a=20
a=a+b #a=30,b=20
b=a-b #b=10,a=30
a=a-b #a=20,b=10
a,b = b,a