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_) 查看内置类型

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