①所有字母都转换为大写
# -*- coding:utf-8 -*- if __name__ == "__main__": a = 'hello, world!' print(a.upper())输出:
HELLO, WORLD!
# -*- coding:utf-8 -*- if __name__ == "__main__": a = 'HELLO, WORLD!' print(a.lower())输出:
hello, world!
# -*- coding:utf-8 -*- if __name__ == "__main__": a = 'HELLO, WORLD!' print(a.capitalize())输出:
Hello, world!
# -*- coding:utf-8 -*- if __name__ == "__main__": a = 'HELLO, WORLD!' print(a.title())输出:
Hello, World!
# -*- coding:utf-8 -*- if __name__ == "__main__": a = 'HELLO, WORLD!' print(a.isupper()) b = 'hello, world!' print(b.isupper())输出:
True False
⑥判断所有字母都为小写
# -*- coding:utf-8 -*- if __name__ == "__main__": a = 'HELLO, WORLD!' print(a.islower()) b = 'hello, world!' print(b.islower())输出:
False True
⑦判断所有单词的首字母为大写
# -*- coding:utf-8 -*- if __name__ == "__main__": a = 'HELLO, WORLD!' print(a.istitle()) b = 'hello, world!' print(b.istitle()) c = 'Hello, World!' print(c.istitle())输出:
False False True