python中str的用法(python中str的用法和作用)

最近有很多读者朋友在python中str使用方法有疑问。有网友整理了相关内容,希望能回答你的疑惑,关于pythonstr本网站还为您找到了问题的答案,希望对您有所帮助。

Python渗透学习(str字符串)

感谢您的关注,小编,我今天又要挖个坑,分享Python的学习笔记。

都说网络安全这条路,python必须学习语言。为什么呢?因为一旦某个漏洞在网上爆发,你必须用Python来编写EXP。这样可以避免不必要的人力,直接脚本检测就可以了。如果你对此没有详细的概念,请阅读我之前的redis获取服务器权限的文章。只要操作脚本,就可以直接代替人省略十几步操作,直接获得权限。方便吗?

从现在开始,我将不断分享我的Python学习笔记,供大家学习。

由于篇幅字数有限,没有办法把所有的笔记都放在这里。有兴趣的读者可以私下谈论我或加入我:92823686收到我所有的笔记。

下图是我想不断分享的Python模块笔记,附有源码解释、中文翻译和各种实例,让您对该模块有更深入的了解。

python中str的用法(python中str的用法和作用)

# capitalize() 第一个字母大写‘’capitalize(…) S.capitalize() -> str Return a capitalized version of S, i.e. make the first character have upper case and the rest lower case.”’#print(help(str.capitalize))a=’asdffghjkl’b=a.capitalize()print(b) # b=Asdffghjkl——————————————————————————————-# casefold() 返回小写,与lower()相似,但lower只针对ASCII,casefold()针对Unicode()”’casefold(…) S.casefold() -> str Return a version of S suitable for caseless comparisons.”’print(help(str.casefold))a=’ASD’b=a.casefold()print(b) # b=asd——————————————————————————————-# 用指定的宽度返回居中版s,# 如有必要,用filchar填充,默认为空格。但是s不会被截取。但是s不会被截取。# 也就是说,如果s的长度大于width,则不会截取s。”’center(…) S.center(width[, fillchar]) -> str Return S centered in a string of length width. Padding is done using the specified fill character (default is a space)”’print(help(str.center))a=’asdfghjkl’b=a.center(20, ‘-‘) # 长度为20,a字符串居中,用数字5填充左右print(b) # b=55555asdfghjkl555555——————————————————————————————-”’count(…) S.count(sub[, start[, end]]) -> int Return the number of non-overlapping occurrences of substring sub in string S[start:end]. Optional arguments start and end are interpreted as in slice notation.”’print(help(str.count))a=’askdfksghjkl’b=a.count(‘k’) # 从下标为1到5计数s’的个数print(b) # b=2——————————————————————————————-# 以 encoding 指定的编码格式编码字符串。errors参数可以指定不同的错误处理方案。”’encode(…) S.encode(encoding=’utf-8′, errors=’strict’) -> bytes Encode S using the codec registered for encoding. Default encoding is ‘utf-8’. errors may be given to set a different error handling scheme. Default is ‘strict’ meaning that encoding errors raise a UnicodeEncodeError. Other possible values are ‘ignore’, ‘replace’ and ‘xmlcharrefreplace’ as well as any other name registered with codecs.register_error that can handle UnicodeEncodeErrors.”’print(help(str.encode))a=’asdfsghjkl’b=a.encode(‘utf-8′)print(b) # b=b’asdfsghjkl’——————————————————————————————-# 判断字符串是否以指定的后缀结束,如果在指定的后缀结束时返回True,否则返回False。# 可选参数”start”与”end“检索字符串的开始和结束。# 可选参数”start”与”end”为了检索字符串的开始和结束。””endswith(…) S.endswith(suffix[, start[, end]]) -> bool suffix — 参数可以是字符串或元素。 start — 字符串中的开始位置。 end — 结束位置在字符中。 Return True if S ends with the specified suffix, False otherwise. With optional start, test S beginning at that position. With optional end, stop comparing S at that position. suffix can also be a tuple of strings to try.”’print(help(str.endswith))a=’asdfsghjk’b=a.endswith(‘k’)c=a.endswith(‘j’)d=a.endswith(‘a’, 0, 1)e=a.endswith(‘a’, 0, 2)print(b) # b=Trueprint(c) # c=Falseprint(d) # d=Trueprint(e) # e=False——————————————————————————————-# 判断字符串是否以指定的后缀结束,如果在指定的后缀结束时返回True,否则返回False。# 可选参数”start”与”end“检索字符串的开始和结束。”’expandtabs(…) S.expandtabs(tabsize=8) -> str Return a copy of S where all tab characters are expanded using spaces. If tabsize is not given, a tab size of 8 characters is assumed.”’print(help(str.expandtabs))a=’asdfsghjk’b=a.endswith(‘k’)c=a.endswith(‘j’)d=a.endswith(‘a’, 0, 1)e=a.endswith(‘a’, 0, 2)print(b) # b=Trueprint(c) # c=Falseprint(d) # d=Trueprint(e) # e=False——————————————————————————————-”’find(…) 检测字符串是否包含子字符串 str , 如果指定 beg(开始)和 end(结束)范围,检查是否包含在指定范围内, 如果包含子字符串,则返回初始索引值,否则返回-1。 S.find(sub[, start[, end]]) -> int Return the lowest index in S where substring sub is found, such that sub is contained within S[start:end]. Optional arguments start and end are interpreted as in slice notation. Return -1 on failure.”’print(help(str.find))a=’asdfsghjk’b=a.find(‘d’)c=a.find(‘f’, 1, 4) #d=a.find(‘f’, 1, 3)print(b) # 2 下标print(c) # 2 从第一个字符到第三个字符,如果找到了,返回下标print(d) # -1——————————————————————————————-”’format(…) # 格式字符串输出(方法与%相似,但是顺序可以指定) S.format(*args, **kwargs) -> str Return a formatted version of S, using substitutions from args and kwargs. The substitutions are identified by braces (‘{‘ and ‘}’).None”’print(help(str.format))name=’ske’fruit=’apple’a=’my name is{},I like{}’.format(name,fruit)b=’my name is{1},I like{0}’.format(fruit,name)c=’my name is{mingzi},I like{shuiguo}’.format(shuiguo=fruit,mingzi=name)print(a) # my name is ske,I like appleprint(b) # my name is StivenWang,I like appleprint(c) # my name is StivenWang,I like apple——————————————————————————————-”’index(…) 检测字符串string中是否包含子字符串 str , 如果存在,则返回str在string中的索引值, 如果指定beg(开始)和 end(结束)范围,则检查是否包含在指定范围内, 该方法与 python find()方法一样,只不过如果str不在 string中会报一个异常(ValueError: substring not found)。 S.index(sub[, start[, end]]) -> int Like S.find() but raise ValueError when the substring is not found.None”’# print(help(str.index))a=”this is string example….wow!!!”b=”exam”#c=a.index(b)d=a.index(b, 20)#print(c) # 15 返回b字符串的第一个字符的索引值print(d) # 报错——————————————————————————————-”’isalnum(…) 检测字符串是否由字母或数字组成 S.isalnum() -> bool Return True if all characters in S are alphanumeric and there is at least one character in S, False otherwise.None”’print(help(str.isalnum))a=”thisisstringexamplewow”b=”123″c=’asdf1234’d=’asdf!@@#’e=’a=”this is string example wow”‘print(a.isalnum()) # True 全部由字母构成print(b.isalnum()) # True 全部由数字构成print(c.isalnum()) # True 全部由字母或者数字构成print(d.isalnum()) # False 有特殊字符print(e.isalnum()) # False 有空格——————————————————————————————-”’isalpha(…) 检测字符串是否只由字母组成 S.isalpha() -> bool Return True if all characters in S are alphabetic and there is at least one character in S, False otherwise.None”’print(help(str.isalpha))a=”thisisstringexamplewow”b=”123″c=’asdf1234’d=’asdf!@@#’e=’a=”this is string example wow”‘print(a.isalpha()) # True 全部由字母构成print(b.isalpha()) # False 有数字print(c.isalpha()) # False 有数字print(d.isalpha()) # False 没有字母print(e.isalpha()) # False 有空格——————————————————————————————-

篇幅有限无法放入所有demo,兴趣的读者可以私聊我或者加群:928233686领取我的所有笔记。

更多资料尽在群:928233686,欢迎加群交流。

主题测试文章,只做测试使用。发布者:艾迪号,转转请注明出处:https://www.cqaedi.cn/baike/46959.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023年 2月 1日 下午4:27
下一篇 2023年 2月 1日 下午5:15

相关推荐

  • 山药粉条的营养价值及功效(山药粉条的营养成分)

    当了妈妈的都有感受,生完孩子以后,就明显感觉你的底子不够用了。都想要好好的补一补。有的人会说去吃山药,虽然是没有错,但是去吃什么样的山药,其实是很有讲究的。山药的品种有很多,但它只分为两种,一种是其他山药,还有一种是垆土山药。 这种山药你不要看它长得丑不拉几的,但是它真的非常的好。古代的大家像张仲景、张锡纯,它们都很喜欢用这种山药。它是记载在李时珍本草纲目里…

    2023年 5月 5日
    00
  • 婚礼男方父亲致辞5篇婚礼男方父亲致辞简短大气讲话稿

    1、婚礼男方父亲致辞5篇 亲爱的亲朋好友们: 今天,我们聚集在这里,见证了两个家庭的联结,共同庆祝这个美好的婚礼。作为新郎的父亲,我感到非常荣幸和自豪。 我要感谢大家的到来,你们的祝福和支持是新婚夫妇最大的动力。感谢新娘的父母,感谢你们的养育之恩,让我们的儿子找到了如此温柔善良的伴侣。 婚姻是人生中的一大事,也是一段新的旅程。我想对新婚夫妇说,婚姻是建立在相…

    百科大全 2023年 9月 13日
    00
  • 五年级班主任工作总结范文8篇最新—五年级语文班主任工作总结

    1、五年级班主任工作总结范文8篇最新 五年级班主任工作总结 作为一名五年级班主任,我深感责任重大,工作充实而有意义。在过去的五年里,我积极参与学生的学习和成长,经历了许多挑战和收获。在这里,我将总结一下我的工作经验和感悟。 我注重学生的全面发展。除了关注他们的学习成绩,我还鼓励他们参加各种课外活动,培养他们的兴趣爱好和综合素质。我组织了各种社团活动,如文学社…

    百科大全 2023年 9月 14日
    00
  • 黑色沙漠为什么不火,黑色沙漠为什么不建议玩

    《黑色沙漠》作为一款大型多人在线角色扮演游戏,虽然在游戏画面、自由度和战斗系统等方面表现出色,但却未能在国内取得与其潜力相符的火爆程度。其原因主要有两方面:一是游戏门槛较高,不够友好;二是缺乏有效的宣传与推广。 1、黑色沙漠为什么不火 《黑色沙漠为什么不火》 《黑色沙漠》是一款由韩国开发商Pearl Abyss制作的大型多人在线角色扮演游戏(MMORPG),…

    百科大全 2023年 6月 27日
    00
  • 凌晨三点半是什么时辰(凌晨三点半醒来是哪个脏器不好)

    因为船上兄弟的英勇事迹,在广州靠港期间,船东宴请全船的兄弟进行了一次丰盛的聚餐,因为大副忙于工作并没能参加,返回到船上我能感受出大副那种斤斤计较的心理,毕竟他和我们的船东是发小,难得的相聚时刻,他却没有把握住,内心的失落我还是可以理解的。凌晨十二点,港口内凉爽的海风吹的人特别舒服,虽然已经是凌晨时分了,但是港口内依旧灯火通明,卸货的码头工人依旧特别有精力地工…

    2023年 5月 24日
    00

站长QQ

7401002

在线咨询: QQ交谈

邮件:7401002@qq.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信