如果我有整数 1988,如何迭代它来查看是否有 double ?在Python中。
我知道我不能像这样迭代它:
userInt = 1988
for i in userInt:
print(i)
最佳答案
您可以将其转换为字符串:
userInt = 1988
for i in str(userInt):
print(i)
如果您想查看是否有 double ,请执行以下操作:
has_doubles = len(set(str(userInt))) == len(str(userInt))
关于python - 在 int 中查找 double ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35931906/