Python 字符串 ljust() 方法Python 字符串方法实例返回 20 个字符长的 "banana" 一词的左对齐版本:txt = "banana"x = txt.ljust(20)print(x, "is my favorite fruit.")完整
Python 字符串 join() 方法Python 字符串方法实例使用哈希字符作为分隔符,将元组中的所有项目连接到字符串中:myTuple = ("Bill", "Steve", "Elon")x = "#".join(myTuple)prin
Python 字符串 isupper() 方法Python 字符串方法实例检查文本中的所有字符是否都大写:txt = "THIS IS NOW!"x = txt.isupper()print(x)完整实例:txt = "THIS IS NOW!"x = txt.
Python 字符串 istitle() 方法Python 字符串方法实例检查每个单词是否以大写字母开头:txt = "Hello, And Welcome To My World!"x = txt.istitle()print(x)完整实例:txt = "He
Python 字符串 isspace() 方法Python 字符串方法实例检查文本中的所有字符是否都是空格:txt = " "x = txt.isspace()print(x)完整实例:txt = " "x = txt.isspace()print(x
Python 字符串 isprintable() 方法Python 字符串方法实例检查文本中的所有字符是否可打印:txt = "Hello! Are you #1?"x = txt.isprintable()print(x)完整实例:txt = "Hello!
Python 字符串 isnumeric() 方法Python 字符串方法实例检查文本中的所有字符是否都是数字:txt = "565543"x = txt.isnumeric()print(x)完整实例:txt = "20491001"x = txt.isnu
Python 字符串 islower() 方法Python 字符串方法实例检查文本中所有字符是否都小写:txt = "hello world!"x = txt.islower()print(x)完整实例:txt = "hello world!"x = txt.is
Python 字符串 isidentifier() 方法Python 字符串方法实例检查字符串是否是有效标识符:txt = "Demo"x = txt.isidentifier()print(x)完整实例:txt = "Demo"x = txt.isidentifi
Python 字符串 isdigit() 方法Python 字符串方法实例检查文本中的所有字符是否都是数字:txt = "50800"x = txt.isdigit()print(x)完整实例:txt = "20491001"x = txt.isdigit()
Python 字符串 isdecimal() 方法Python 字符串方法实例检查 unicode 对象中的所有字符是否都是小数:txt = "\u0033" #unicode for 3x = txt.isdecimal()print(x)完整实例:txt
Python 字符串 isalpha() 方法Python 字符串方法实例检查文本中的所有字符是否都是字母:txt = "CompanyX"x = txt.isalpha()print(x)完整实例:txt = "CompanyX"x = txt.isalph
Python 字符串 isalnum() 方法Python 字符串方法实例检查文本中的所有字符是否都是字母数字:txt = "Company12"x = txt.isalnum()print(x)完整实例:txt = "Company12"x = txt.
Python 字符串 index() 方法Python 字符串方法实例文字中 "welcome" 一词在哪里?txt = "Hello, welcome to my world."x = txt.index("welcome")print(x)完整实例:txt = "Hell
Python 字符串 format() 方法Python 字符串方法实例将价格插入占位符内,价格应为定点,两位十进制格式:txt = "For only {price:.2f} dollars!"print(txt.format(price = 49))完