随笔分类 - Python.函数
摘要:https://www.runoob.com/python/att-string-format.html Python2.6 开始,新增了一种格式化字符串的函数 str.format(),它增强了字符串格式化的功能。 基本语法是通过 {} 和 : 来代替以前的 % 。 format 函数可以接受不限
阅读全文
摘要:常用代码,单拎出来以备查。 对象存json文件: import json obj={'name':'张有财','age':39,'arr':[2,34,5,6,7,88,'李有钱']} with open('./obj.json','w',encoding='utf-8') as fObj: jso
阅读全文
摘要:代码: # bytes转字符串方式一 b=b'\xe9\x80\x86\xe7\x81\xab' string=str(b,'utf-8') print(string) # bytes转字符串方式二 b=b'\xe9\x80\x86\xe7\x81\xab' string=b.decode() #
阅读全文
摘要:# 例子: target='www.163.com' print(target.find('163')) if target.find('263') 1: print('263不存在于字符串'+target+'中') 运行: C:\Users\horn1\Desktop\python\7>pytho
阅读全文