# Strings have many methods wo can use rand_string=" life is a beautiful struggle " print("去除左边空格:",rand_string.lstrip()) print("去除右边的空格:",rand_string.rstrip()) print("去除两边的空格:",rand_string.strip()) print() rand_str…
这是本人在学习python过程中总结的一些关于字符串的常用的方法. 文中引用了python3.5版本内置的帮助文档,大致进行翻译,并添加了几个小实验. isalnum S.isalnum() -> bool #字符串里所有的字符都是字母或者数字时返回True,否则返回False Return True if all characters in S are alphanumeric and there is at least one character in S, False otherwise.…