温馨提示×

python怎么判断字符串类型

小亿
111
2023-09-15 23:44:24
栏目: 编程语言

在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’>,表示它们都是字符串类型。

0