扫描二维码下载沐宇APP

沐宇

微信扫码使用沐宇小程序

沐宇

python怎么判断字符串类型

扬州沐宇科技
2023-09-15 23:44:24
python

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

扫码添加客服微信