判断列表中元素示例
list1 = [321,354,764,5,87,3,0,25];
if(0 in list1):
print("里面有0存在");
else:
print("里面没有0存在");
list1 = ["321","354","764","5","87","3","0","25"];
if("0" in list1):
print("里面有0存在");
else:
print("里面没有0存在");
list1 = "423423";
if("0" in list1):
print("里面有0存在");
else:
print("里面没有0存在");
t1 = [1,2,3,4,511];
if([1,2] in t1):
print("里面有[1,2]存在");
else:
print("里面没有[1,2]存在");
if([1,2] in [[1,2],3,5,3]):
print("里面有[1,2]存在");
else:
print("里面没有[1,2]存在");
字符串(lower,count,find)
s = "John Smith";
print(s);
print("使用小写函数后",s.lower());
print("'hn'在第",s.find("hn"),"位");
print("'handsome'在第",s.find("handsome"),"位");
if("hn" in s):
print("'hn'在第", s.find("hn"), "位");
else:
print("'hn'不在s内");
s = [32,453,643,7,0,423,45,0,422,654,4,43,0,53];
count = s.count(0);
s1 = str(s);
print(s1);
n=0;
for i in range(count):
print("0在列表中第",s1.find('0',n));
n = s1.find('0',n) +1;