python 系列学习-1

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/yangfengling1023/article/details/81704044

1、python获取当前字符串编码格式 chardet

安装:pip install chardet

在python2中,经常会遇到编码的问题,在python中有一个包可以打印出当前字符串的编码格式,具体的如下所示

import chardet

print chardet.detect(html)

如图所示:

测出的编码是ascii,其中confidence字段为1.0,表示检测的概率是1.0(即100%)

2、python将列表的元素转换成字典的形式 zip

zip的使用:

网址http://www.runoob.com/python/python-func-zip.html

3、将两个列表中的元素进行一一相加

a=[1,2,3]
b=[4,5,6]
c=[a[i]+b[i] for i in range(len(a))]

如下图所示:

猜你喜欢

转载自blog.csdn.net/yangfengling1023/article/details/81704044