python数据类型

字符串去除空白 ,strip() , 包括空格,tab键, 换行符

>>> name = ” frank ”
>>> name.strip()
‘frank’

字符串的分割, split(“分隔符”),分组后成为一个列表

>>> name = “apple, banbana, orice”
>>> name.split(“,”)
[‘apple’, ‘ banbana’, ‘ orice’]
>>>

字符串的合并 join(“连接符”)

>>> name = [‘frank’, ‘marlon’, ‘lee’]
>>> “|”.join(name)
‘frank|marlon|lee’

判断空格是否子字符串中 “in”

>>> name = “frank bain”
>>> ” in name
true
>>> “l” in name
false
>>>

两种字符串格式化打印形式 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’
>>>

字符串的判断

>>> name = “frank”
>>> name.upper()
‘frank’
>>> name.lower()
‘frank’
>>> name.startswith(“f”)
true
>>> name.endswith(“k”)
true
>>> name.endswith(“a”)
false

Posted in 未分类

发表评论