温馨提示×

python怎么判断字符串类型

小亿
171
2023-09-15 23:44:24
栏目: 编程语言
Python开发者专用服务器限时活动,0元免费领,库存有限,领完即止! 点击查看>>

在Python中,可以使用type()函数来判断字符串的类型。例如:

string1 = "Hello, world!"
string2 = "12345"
string3 = "3.14"
print(type(string1))  # <class 'str'>
print(type(string2))  # <class 'str'>
print(type(string3))  # <class 'str'>

在上述代码中,使用type()函数分别判断了三个字符串的类型,结果都是<class ‘str’>,表示它们都是字符串类型。

亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>

推荐阅读:python中如何用if判断字符串类型

0