在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判断字符串类型