【发布时间】:2021-04-02 14:21:39
【问题描述】:
我想创建检查条件字符串是否为字符串编号 那么,我该如何在 python 中做呢
x = "String"
y = "12"
if x is string:
print("this is string")
if y is string:
print("this is not string")
【问题讨论】:
-
你在if条件下设置的
string是什么? -
if x is string如果要检查 x 的 type,这是错误的方法。请改用if type(x) is str。 -
x和y都是 Python 字符串。
标签: python string if-statement