python_string_learning

发布时间:2022-06-27 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了python_string_learning脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

# author: Roy.Ga="my name is t roy.guo,i am {year} years old,i like {frute}"print(a.center(60,"-")) # .center print 50 character,center the string and fill the gap with -print(a.capitalize()) #change the tring first letter whth capital letter.print(a.count("o")) #count the letter or stringprint(a.endswith("oy")) #determine if the string ends with an “oy”print(a.expandtabs(30)) # define the length of the "/t"print(a.find("roy.guo")) # beginning index of the "roy.guo"print(a.format(year="twenty-six",frute="appl")) # specifies the value of {}print(a.format_map({"year":"23","frute":"orange"})) #make a map to find match the {}print("ab123".isalnum())print("aba".isalpha())print("100".isdigit())print("200".isdecimal())print("0a100".isidentifier())print("33.33".isnumeric())print("My Name Is Roy".istitle())print("+".join(["1","2","3","4"]))print("nroy")print("nroy".lstrip())print("nroyn".rstrip())print("nroy".strip()) # strip the n and spacep=str.maketrans("abcdefg","1234567")pa="my name is abc".translate(p)print("my name is abc".translate(p)) #translate character to characterpt=str.maketrans("1234567","abcdefg")pb=pa.translate(pt)print(pb) #swap the code to decodeprint("roy".replace("r","R"))print("r my name is roy".rfind("r")) #find the rightmost lettter "r"print("r my name is roy".split("r")) #split string by "r" to a listprint("1+2+n3+4".splitlines())print("r my name is roy".title())

脚本宝典总结

以上是脚本宝典为你收集整理的python_string_learning全部内容,希望文章能够帮你解决python_string_learning所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: