Home >Backend Development >Python Tutorial >python data type --- string
Remove whitespace from strings, strip(), including spaces, tab keys, newlines
>>> name = " Frank " >>> name.strip() 'Frank'
Split strings, split("separator"), group into a list
>>> name = "Apple, banbana, orice" >>> name.split(",") ['Apple', ' banbana', ' orice'] >>>
Merge join("connection of strings symbol ")
>>> name = ['Frank', 'Marlon', 'Lee'] >>> "|".join(name) 'Frank|Marlon|Lee'
Judge whether a space is "in" in a substring
>>> name = "Frank Bain" >>> '' in name True >>> "L" in name False >>>
Two string formatting and printing forms format
# 第一种表示方法 >>> msg = "Hello {name}, your age is {age}" >>> msg.format(name="Frank", age=24) 'Hello Frank, your age is 24' >>> # 第二种表示方法 ,注意index 从0 开始 >>> msg = "Hello{0}, your age is {1}, sex is {2}" >>> msg.format("Frank", 24, "man") 'HelloFrank, your age is 24, sex is man' >>>
Judgment of string
>>> name = "Frank" >>> name.upper() 'FRANK' >>> name.lower() 'frank' >>> name.startswith("F") True >>> name.endswith("k") True >>> name.endswith("a") False