Python 字符串 istitle()方法

Python 字符串 istitle()方法

Python istitle() 方法返回True,如果字符串是标题化的字符串。否则返回False。

语法

istitle()

参数

不需要参数。

返回值

返回True或False。

让我们看一些istitle()方法的示例,以了解其功能。

示例1

这是一个简单的例子,用于理解。

# Python istitle() method example
# Variable declaration
str = "Welcome To Javatpoint"
# Calling function
str2 = str.istitle()
# Displaying result
print(str2)

示例2

# 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

示例3

# 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

Camera课程

Python教程

Java教程

Web教程

数据库教程

图形图像教程

办公软件教程

Linux教程

计算机教程

大数据教程

开发工具教程