Python3.7知其然知其所以然-第六章 字符串( 九 )


print(s.startswith(\"You\"))

(4)判断是否是指定的字符串结束 , 是的话 , 返回True , 否则返回False 。 可以从指定的范围进行查找它的语法是:str.endswith(str beg=0end=len(string)) 。

# 字符串内容

s = \"I am a handsome boy.\"

# 找到返回True

print(s.endswith(\".\"))

# 从指定范围进行查找 , 找不到 , 返回False

print(s.endswith(\".\" 2 6))

# 没找到返回False?

print(s.endswith(\"e\"))

6.8大小写

英文单词 , 大小写转换 。 可以从大写转成小写 , 也可以从小写转成大写 。

(1)通过upper()函数 , 把字母全部转换化为大写 。

推荐阅读