python 數據結構+算法

數據結構:
存儲和使用數據的方式
算法:
解決問題的步驟

解決一個問題的時候,分析問題,設計算法,編寫程序,調試,出結果

變量:可以改變的
常量:不可以改變的

變量類型: 不同類型的變量存儲不同類型的值
python 弱語言類型,不需要顯示的聲明變量 ,但需要定義,即給變量賦值

1 是在內存中保存的
a 是一個指針 指針存的是在內存中的地址,使用a的時候,可以訪問到內存中的1

a is 1 如果爲true的話,要求a和1 在內存中的地址一樣

NameError: name ‘a’ is not defined
1、沒有賦值
2、變量名輸入錯誤

>>> print (a)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'a' is not defined
>>> a=1
>>> id(1)
493052128
>>> id(a)
493052128
>>> a is 1
True
>>>

IndexError: list index out of range
條件反射:
需要看一下是不是寫的index值超過了列表的長度。
2個動作:
1 增加列表長度
2 改小index的值

類型:

>>> b=1.0
>>> type(b)
<class 'float'>
>>> c="abc"
>>> type(c)
<class 'str'>
>>> d=b'abc'
>>> type(d)
<class 'bytes'>
>>> e=1+1j
>>> type(e)
<class 'complex'>
>>> list=[]
>>> del list
>>> l=[]
>>> type(l)
<class 'list'>
>>> t=(1,2)
>>> type(t)
<class 'tuple'>
>>> d={1:2}
>>> type(d)
<class 'dict'>
>>> s=set([1,2,2,4])
>>> type(s)
<class 'set'>
>>> s
{1, 2, 4}
>>> s1=frozenset({1,2})
>>> type(s1)
<class 'frozenset'>

dir(_builtins_) 查看內置類型

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章