class str(object="")
class str(object=b'', encoding='utf-8', errors='strict')

将其他对象转化为字符串对象。

例子:

>>> str()
''
>>> str()
''
>>> file = open('data.txt','rb')
>>> fb = file.read()
>>> str(fb)
"b'\\xe5\\xa4\\xa9\\xe7\\x8e\\x8b\\xe7\\x9b\\x96\\xe5\\x9c\\xb0\\xe8\\x99\\x8e\\xef\\xbc\\x8c\\xe5
\\xb0\\x8f\\xe9\\xb8\\xa1\\xe7\\x82\\x96\\xe8\\x98\\x91\\xe8\\x8f\\x87\\xe3\\x80\\x82'"
>>> str(fb,'utf-8') #指定编码集
'天王盖地虎,小鸡炖蘑菇。'
>>> str(fb,'gbk','ignore') #指定报错级别
'澶╃帇鐩栧湴铏庯紝灏忛浮鐐栬槕鑿囥'
>>> file.close()

Python内置函数之str()的更多相关文章

  1. Python内置函数(12)——str

    英文文档: class str(object='') class str(object=b'', encoding='utf-8', errors='strict') Return a string  ...

  2. Python内置函数(61)——str

    英文文档: class str(object='') class str(object=b'', encoding='utf-8', errors='strict') Return a string ...

  3. python内置函数

    python内置函数 官方文档:点击 在这里我只列举一些常见的内置函数用法 1.abs()[求数字的绝对值] >>> abs(-13) 13 2.all() 判断所有集合元素都为真的 ...

  4. python 内置函数和函数装饰器

    python内置函数 1.数学相关 abs(x) 取x绝对值 divmode(x,y) 取x除以y的商和余数,常用做分页,返回商和余数组成一个元组 pow(x,y[,z]) 取x的y次方 ,等同于x ...

  5. Python内置函数进制转换的用法

    使用Python内置函数:bin().oct().int().hex()可实现进制转换. 先看Python官方文档中对这几个内置函数的描述: bin(x)Convert an integer numb ...

  6. Python 内置函数笔记

    其中有几个方法没怎么用过, 所以没整理到 Python内置函数 abs(a) 返回a的绝对值.该参数可以是整数或浮点数.如果参数是一个复数,则返回其大小 all(a) 如果元组.列表里面的所有元素都非 ...

  7. 【转】python 内置函数总结(大部分)

    [转]python 内置函数总结(大部分) python 内置函数大讲堂 python全栈开发,内置函数 1. 内置函数 python的内置函数截止到python版本3.6.2,现在python一共为 ...

  8. python内置函数,匿名函数

    一.匿名函数 匿名函数:为了解决那些功能很简单的需求而设计的一句话函数 def calc(n): return n**n print(calc(10)) #换成匿名函数 calc = lambda n ...

  9. python 内置函数总结(大部分)

    python 内置函数大讲堂 python全栈开发,内置函数 1. 内置函数 python的内置函数截止到python版本3.6.2,现在python一共为我们提供了68个内置函数.它们就是pytho ...

随机推荐

  1. Python的程序结构[2] -> 类/Class[5] -> 内建类 bytes 和 bytearray

    内建类 bytes 和 bytearray / Built-in Type bytes and bytearray 关于内建类 Python的内建类 bytes 主要有以下几点: class byte ...

  2. [POI2014]Ant colony

    题目大意: 给定一棵$n(n\le10^6)$个结点的树.在每个叶子结点,有$g$群蚂蚁要从外面进来,其中第$i$群有$m_i$只蚂蚁.这些蚂蚁依次爬树(一群蚂蚁爬完后才会爬另一群),若当前经过结点度 ...

  3. SimpleDateFormat格式

      SimpleDateFormat函数语法:      G 年代标志符   y 年   M 月   d 日   h 时 在上午或下午 (1~12)   H 时 在一天中 (0~23)   m 分   ...

  4. python 人工智论

    https://www.zhihu.com/question/21395276 基于python深度学习库DeepPy的实现:GitHub - andersbll/neural_artistic_st ...

  5. linux tail指令

    http://www.cnblogs.com/peida/archive/2012/11/07/2758084.html tail -f file,  check the log file tail  ...

  6. 常用VBA小技巧

    用对话框选取文件路径(单个文件) 删除导入csv等文本文件后留下的 Data connections 增加新的工作表并并命名 Worksheets.Add(After:=Worksheets(Work ...

  7. python 文件操作的注意事项

    我们经常用python读取文件信息,这里有些注意事项 with open('test.txt', 'r') as f: print 'f.read', f.read() with open('test ...

  8. 【Consul】 分布式环境中的服务注册和发现利器

    参考资料: http://www.cnblogs.com/shanyou/p/4695131.html http://blog.csdn.net/viewcode/article/details/45 ...

  9. Elasticsearch安装(四), elasticsearch head 插件安装和使用。

    安装方式如下: 一.安装Elasticsearch-Head 1.插件安装方式(推荐) #在Elasticsearch目录下 $/bin/plugin -install mobz/elasticsea ...

  10. iOS_block代码块

    watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcHJlX2VtaW5lbnQ=/font/5a6L5L2T/fontsize/400/fill/I0JBQk ...