python id 的 is 記憶體位址

2022-09-20 03:00:11 字數 4027 閱讀 9659

1,id() 記憶體位址

2.==比較的是值

3.is 比較的是記憶體位址

數字,字串,有小資料池

int -5--256

str:1,不能有空格

2.長度不能超過20個字元

3.不能有特殊字元如:#@....

1.id() 記憶體位址

1 # id() 記憶體位址

2 s = 'alex'

3 print(s,type(s),id(s))

4 # alex 35619648

5 # alex 32146240

2.== 比較的是值

3.is 比較的是記憶體位址

3.1列表、字典、元祖、set集合
1 # 列表、字典、元祖、set集合

2 l1 = [1,2,3]

3 l2 = [1,2,3]

4 print(l1 == l2) # true

5 print(id(l1),id(l2)) # 35680008 35679368

6 print(l1 is l2) #false

# 字串、數字的特殊的。比較記憶體位址,pc看不出來,用cmd來檢視s1 = 'alex  '

3.2對於str 小資料池

# 範圍

1.不能有空格。

2.長度不能超過20位。

3.不能有特殊字元。#@...

cmd ---------》str

1 # 有空格指向的是false

2 >>> i = 'a'

3 >>> i1= 'a'

4 >>> print(i is i1)

5 true

6 7 >>> s1 = 'alex '

8 >>> s2 = 'alex '

9 >>> print(s1 == s2)

10 true

11 >>> print(s1 is s2)

12 false

13 14 >>> i = 'a b'

15 >>> i1= 'a b'

16 >>> print(i is i1)

17 false

1 # 超過20位則為false

2 >>> i = 'a'*20

3 >>> j = 'a'*20

4 >>> print(i is j)

5 true

6 >>> i = 'a'*21

7 >>> j = 'a'*21

8 >>> print(i is j)

9 false

1 # 有特殊字元也為false

2 >>> i = 'a@'

3 >>> j = 'a@'

4 >>> print(i is j)

5 false

3.3對於int 小資料池cmd  ---------》int

1 >>> i = 6

2 >>> i1= 6

3 >>> print(i is i1)

4 true

5 >>> i = 258

6 >>> i1= 258

7 >>> print(i is i1)

8 false

9 >>> i = -5

10 >>> i1= -5

11 >>> print(i is i1)

12 true

1,id() 記憶體位址

2.==比較的是值

3.is 比較的是記憶體位址

數字,字串,有小資料池

int -5--256

str:1,不能有空格

2.長度不能超過20個字元

3.不能有特殊字元如:#@....

1.id() 記憶體位址

1 # id() 記憶體位址

2 s = 'alex'

3 print(s,type(s),id(s))

4 # alex 35619648

5 # alex 32146240

2.== 比較的是值

3.is 比較的是記憶體位址

3.1列表、字典、元祖、set集合
1 # 列表、字典、元祖、set集合

2 l1 = [1,2,3]

3 l2 = [1,2,3]

4 print(l1 == l2) # true

5 print(id(l1),id(l2)) # 35680008 35679368

6 print(l1 is l2) #false

# 字串、數字的特殊的。比較記憶體位址,pc看不出來,用cmd來檢視s1 = 'alex  '

3.2對於str 小資料池

# 範圍

1.不能有空格。

2.長度不能超過20位。

3.不能有特殊字元。#@...

cmd ---------》str

1 # 有空格指向的是false

2 >>> i = 'a'

3 >>> i1= 'a'

4 >>> print(i is i1)

5 true

6 7 >>> s1 = 'alex '

8 >>> s2 = 'alex '

9 >>> print(s1 == s2)

10 true

11 >>> print(s1 is s2)

12 false

13 14 >>> i = 'a b'

15 >>> i1= 'a b'

16 >>> print(i is i1)

17 false

1 # 超過20位則為false

2 >>> i = 'a'*20

3 >>> j = 'a'*20

4 >>> print(i is j)

5 true

6 >>> i = 'a'*21

7 >>> j = 'a'*21

8 >>> print(i is j)

9 false

1 # 有特殊字元也為false

2 >>> i = 'a@'

3 >>> j = 'a@'

4 >>> print(i is j)

5 false

3.3對於int 小資料池cmd  ---------》int

1 >>> i = 6

2 >>> i1= 6

3 >>> print(i is i1)

4 true

5 >>> i = 258

6 >>> i1= 258

7 >>> print(i is i1)

8 false

9 >>> i = -5

10 >>> i1= -5

11 >>> print(i is i1)

12 true

記憶體位址分配

inti 1 intj 1 cout i endl j endl 2 函式引數列表的存放方式是,先對最右邊的形參分配位址,後對最左邊的形參分配位址。3 little endian模式的cpu對運算元的存放方式是從低位元組到高位元組的 0x1234的存放方式入下 0x4000 0x34 0x4001 ...

理解記憶體位址

物理記憶體 記憶體條實際提供的記憶體空間 記憶體定址 在記憶體上找到正確的位置以便進行訪問的過程 硬編碼 通過實體地址操作物理記憶體的寫碼方式 線性記憶體和物理記憶體 相似點 從0編號,線性增加 不同 1.實體地址一一對應於實際物理記憶體空間的位置,而線性位址可多對一 多個線性位址對應乙個實體地址 ...

記憶體位址對齊

記憶體位址對齊,是一種在計算機記憶體中排列資料 訪問資料的一種方式,包含了兩種相互獨立又相互關聯的部分 基本資料對齊和結構體資料對齊。當今的計算機在計算機記憶體中讀寫資料時都是按字 word 大小塊來進行操作的 在32位系統中,資料匯流排寬度為32,每次能讀取4位元組,位址匯流排寬度為32,因此最大...