小码哥的IT人生

Python 字符串 istitle() 方法

Python基础 2022-06-06 15:21:25小码哥的IT人生shichen

Python 字符串 istitle() 方法

实例

检查每个单词是否以大写字母开头:

txt = "Hello, And Welcome To My World!"
x = txt.istitle()
print(x)

完整实例:

txt = "Hello, And Welcome To My World!"
x = txt.istitle()
print(x)

定义和用法

如果文本中的所有单词均以大写字母开头,而单词的其余部分均为小写字母,则 istitle() 方法返回 True。否则返回 False。

符号和数字将被忽略。

语法

string.istitle()

参数值

无参数.

更多实例

示例代码:

检查每个单词是否以大写字母开头:

a = "HELLO, AND WELCOME TO MY WORLD"
b = "Hello"
c = "22 Names"
d = "This Is %'!?"
print(a.istitle())
print(b.istitle())
print(c.istitle())
print(d.istitle())

完整实例:

a = "HELLO, AND WELCOME TO MY WORLD"
b = "Hello"
c = "22 Names"
d = "This Is %'!?"
print(a.istitle())
print(b.istitle())
print(c.istitle())
print(d.istitle())

版权所有 © 小码哥的IT人生
Copyright © phpcodeweb All Rights Reserved
ICP备案号:苏ICP备17019232号-2  

苏公网安备 32030202000762号

© 2021-2024