在python中可以通过in和not in关键字来判读一个list中是否包含一个元素 pythontab = ['p','y','t','h','o','n','t','a','b'] if 't' in pythontab: print 't in pythontab' if 'w' not in theList: print 'w is not in pythontab'
在实际写程序中,经常要对变量类型进行判断,除了用type(变量)这种方法外,还可以用isinstance方法判断: #!/usr/bin/env pythona = 1b = [1,2,3,4]c = (1,2,3,4)d = {‘a‘:1,‘b‘:2,‘c‘:3}e = "abc"if isinstance(a,int): print "a is int"else: print "a is not int"if isinstance
python 判断字符串中是否只有中文字符 学习了:https://segmentfault.com/q/1010000007898150 def is_all_zh(s): for c in s: if not ('\u4e00' <= c <= '\u9fa5'): return False return True