Python中6種基本資料型別

2021-09-25 22:13:12 字數 631 閱讀 2488

基本資料型別包括:

不可變資料:number(數字);string(字串);tuple(元組)

可變資料:list(列表);set(集合);dictionary(字典)

有序序列:string,tuple,list

無序序列:set,dictionary

number:

int整數型別

float

浮點型別

bool

布林型別

complex

複數型別

type()

變數的物件型別

isinstance()

判斷變數所指型別是否是某型別

del()

刪除變數

string:

索引值以0開始,-1為從末尾的開始位置

tuple:

tuple=(1,2,3,4)

tuple=(1,) #當只有乙個元素時也需要加逗號

list:

list=[1,2,3,4]

dictionary:

dic= 

dic={}#空字典

key值唯一

set:

過濾重複元素

set=set([1,2,3,4])

Python3的基本資料型別6種

不可變資料型別 3個 number,string,tuple 可變資料型別 3個 list,dictionary,set number 數字 python3 支援int,float,bool,complex 複數 整型 int 通常被稱為整型或整數,可以是正整數或負整數,不帶小數點。python3 ...

python基本資料型別

物件是python中最基本的概念,python中資料以物件的形式出現 無論是python提供的內建物件,還是使用python或是像c擴充套件庫這樣的擴充套件語言工具建立的物件。物件時記憶體中的一部分,包括數值和相關操作的集合。python程式可以分解成模組 語句 表示式以及物件,如下 1 程式由模組...

Python基本資料型別

1 python中一切都是物件。2 每乙個資料都有乙個id標示,用id 可以檢視。也可以用type檢視是什麼型別。3 常用的資料型別 int 整型 數字 boole true 值 賦值,要用大寫 a true string 字串 也稱作序列。list 列表 tuple 元組 dict 字典 set ...