一.字符串 特性:字符串本身不可修改,除非字符串变量重新赋值.Python3中所有字符串都是Unicode字符串,支持中文. >>> name = "Jonathan" >>> name = "Jonathan" + "Ni" >>>print(name) Jonathan Ni # name 被重新赋值,并不是改变原先字符串 "Joanthan" 字符串运算符 实例…
格式化输出 name = input("请输入你的名字:") age = input("请输入你的年龄:") msg = ''' -------------info of %s---------- name : %s age : %s ---------------end---------------- '''%(name,name,age) print(msg) # exit("程序已退出!") # 强制退出程序 if age.isdigit(…
方法一: with open("e:\\gloryroad.txt","a+",encoding="utf-8") as file: file.write("------"+"\n") print(file.tell()) 备注:使用此方式操作文件,可以不用写close()关闭文件命令,操作完,程序会自动关闭 -------------------------------------------------…
一.replace()函数1用字符串本身的replace方法: a = 'hello word' b = a.replace('word','python') print b 1 2 3 二.re.sub() import re a = 'hello word' strinfo = re.compile('word') b = strinfo.sub('python',a) print b…