Python 如何在字符串的任意位置查找特定数字
问题在于变量Python 如何在字符串的任意位置查找特定数字,python,Python,问题在于变量e您应该首先将整数转换为字符串,以便执行类似字符串的搜索,如: import math import random a = random.random() b = random.random() c = random.random() d = a*b*c e = 14 print ("a = {0}".format(a)) print ("b = {0}".format(b)) print ("c = {0}".format(c)) print ("d = {0}
e
您应该首先将整数转换为字符串,以便执行类似字符串的搜索,如:
import math
import random
a = random.random()
b = random.random()
c = random.random()
d = a*b*c
e = 14
print ("a = {0}".format(a))
print ("b = {0}".format(b))
print ("c = {0}".format(c))
print ("d = {0}".format(d))
if "e" in d:
print("Value found")
else:
print("Value not found")
替换:
if str(e) in str(d):
与:
演示:
您可以通过以下方式执行此操作:
>>> e=12
>>> d=45123
>>> str(e) in str(d)
True
你什么意思:我想在任何位置找到一个数字?
if str(e) in str(d):
>>> e=12
>>> d=45123
>>> str(e) in str(d)
True
list=[]
for x in range(2,d):
if d%x==0:
list.append(x)
if e in list:
print ("e is a multiplier")
else:
print("e is not a multiplier")