python 第二次预习课补充

set 排重
frozenset={[1,2,3,3,4]}

>>> e=1+1j
>>> type(e)
<class 'complex'>
>>> list=[]
>>> del list
>>> i=[]
>>> type(i)
<class 'list'>
>>> t=(1,2)
>>> type(t)
<class 'tuple'>
>>> d={1:2}
>>> type(d)
<class 'dict'>
>>> s=set([1,2,2,2])
>>> type(s)
<class 'set'>
>>> s
{1, 2}
>>> d1=frozenset([1,2,2,2,3])
>>> type(d1)n
  File "<stdin>", line 1
    type(d1)n
            ^
SyntaxError: invalid syntax
>>> type(d1)
<class 'frozenset'>
>>> d1
frozenset({1, 2, 3})
True
False
type(True) bool

内置类型
dir

运算方法:

>>> a=1
>>> b+1
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'b' is not defined
>>> b=1
>>> a+b
2
>>> a-b
0
>>> a*b
1
>>> a/b
1.0
>>> a%b
0
>>> a**b
1
>>> import math
>>> math.sqrt(b)
1.0

>>> import math
>>> math.sqrt(b)
1.0
>>> pow(2,3)
8
>>> 2//4
0
>>> 6//2
3
>>> floor(1/2)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'floor' is not defined
>>> math.floor(1/2) 地板向下
0
>>> math.ceil(1/2) 地板向下
1
>>> round(0.3) 四舍五入
0
>>> round(0.)
0
>>> round(0.9)
1

‘list’ object is not callable    xx对象不能被调用
保留字被改变
恢复:
del list

>>> list("a,b,c")
['a', ',', 'b', ',', 'c']
>>> list=1
>>> list("abc")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'int' object is not callable
>>> del list
>>> list("a,b,c")
['a', ',', 'b', ',', 'c']
>>>

字符串
编码:
ascii 码

gb2312
gbk
big5

unicode: key 1–>value字符(各种语言:韩文、中文、英文)

utf-8
utf-16
utf-32
保存文件 Unicode的存储编码
py3
s=”中国”
type(s) str类型 Unicode
s1=b”avc” –tytes类型 — (gbk,utf-8)

s.encode(“utf-8”)—> bytes类型
s.encode(“utf-8”).decode(“utf-8”)—>unicode 类型

py2
s=”中国”
type(s) str类型 不是Unicode 累死bytes对象
s1=b”avc” –tytes类型 — (gbk,utf-8)

s.decode(“utf-8”)—> Unicode
s.decode(“utf-8”).encode(“utf-8”)—>str 类型

unicode(s=”abc”) –encode–tytes
bytes(s=b”abc”)—decode–unicode

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值