(三)Python入門筆記(資料型別)

2021-10-03 18:07:45 字數 657 閱讀 4547

一、內建資料型別

資料型別

資料型別

文字型別

str數值型別

int, float, complex(複數)

序列型別

list, tuple, range

對映型別

dict

集合型別

set, frozenset

布林型別

bool

二進位制型別

bytes, bytearray, memoryview

二、獲取資料型別

可以使用 type() 函式獲取任何物件的資料型別:

x =

1print

(type

(x))

三、設定資料型別

四、設定特定的資料型別

*資料型別轉換

eval() 把字串轉換為資料本身的資料型別

str

='(1,2)'

print

(type

(eval

(str))

)#

Python筆記 資料型別

注 平時寫 養成習慣用單引號 括起來字串,因為乙個鍵就可以,而且跟mysql的用法相同 1 單引號 或者雙引號 括起來的字串都是一樣的,舉例 1 print hello 2 print hello 1和2,結果都是hello 2 如果單引號 本身也是個字元 1 可以用雙引號 括起來,比如print ...

python學習筆記(資料型別)

1,list 可以儲存各種資料型別甚至可以巢狀使用,使用方法同字串。用 賦值。元素可變。1 刪除操作 del 例如 list a b c del list 1 則此時的list為 a c 2 得到長度 len list 3 返回最大值最小值 max list min list 4 在結尾新增新物件 ...

Python學習筆記 資料型別

python的資料型別 分為整數,浮點數,字串,布林值,空值 python可以處理任意大小的整數,當然包括負整數,在python程式中,整數的表示方法和數學上的寫法一模一樣,例如 1,100,8080,0,等等。計算機由於使用二進位制,所以,有時候用十六進製制表示整數比較方便,十六進製製用0x字首和...