📅  最后修改于: 2020-10-30 06:25:47             🧑  作者: Mango
如果字符串是带有标题的字符串, Python的istitle()方法将返回True。否则返回False。
istitle()
不需要任何参数。
它返回True或False。
我们来看一些istitle()方法的示例,以了解其功能。
这是一个简单的例子
# Python istitle() method example
# Variable declaration
str = "Welcome To Javatpoint"
# Calling function
str2 = str.istitle()
# Displaying result
print(str2)
# Python istitle() method example
# Variable declaration
str = "Welcome To Javatpoint" # True
# Calling function
str2 = str.istitle()
# Displaying result
print(str2)
str = "hello javatpoint" # False
str2 = str.istitle()
print(str2)
输出:
True
False
# Python istitle() method example
# Variable declaration
str = "ab cd ef"
if str.istitle() == True:
print("In title case")
else:
print("Not in tit0le case")
str = "Ab Cd Ef"
if str.istitle() == True:
print("In title case")
else:
print("Not in title case")
str = "1b 2d 3f"
if str.istitle() == True:
print("In title case")
else:
print("Not in title case")
输出:
Not in title case
In title case
Not in title case