python代码取linesplit2的前三位判断是否为215
可以使用切片操作来取得前三位,然后使用条件判断语句进行判断。
代码示例:
linesplit = "215123456".split()
if linesplit[2][:3] == "215":
print("前三位为215")
else:
print("前三位不为215")
输出结果:
前三位为215
原文地址: https://www.cveoy.top/t/topic/i5Ou 著作权归作者所有。请勿转载和采集!