1.Python中关系运算符in,not in在字符串表达式和列表的使用时有什么区
Membership test operations
For container types such as list, tuple, set, frozenset, dict, or collections.deque, the expression x in y is equivalent to any(x is e or x == e for e in y).
For the string and bytes types, x in y is True if and only if x is a substring of y. An equivalent test is y.find(x)!= -1. Empty strings are always considered to be a substring of any other string, so "" in "abc" will return True.
翻译:
对容器类型,例如list、tuple、set、frozenset、dict或collections.deque,表达式x in y等价于any(x is e or x == e for e in y)。
对字符串和bytes类型,x in y为真当且仅当x是y的子串。等价测试为y.find(x) != -1。空字符串永远被视作是其他任何字符串的子集,因此"" in "abc"将返回True。
2.python中如何使用not in
name=''while not name: name=raw_input(u'请输入姓名:')print namepython中的not具体表示是什么:在python中not是逻辑判断词,用于布尔型True和False,not True为False,not False为True,以下是几个常用的not的用法:(1) not与逻辑判断句if连用,代表not后面的表达式为False的时候,执行冒号后面的语句。
比如:a = Falseif not a: (这里因为a是False,所以not a就是True) print "hello"这里就能够输出结果hello(2) 判断元素是否在列表或者字典中,if a not in b,a是元素,b是列表或字典,这句话的意思是如果a不在列表b中,那么就执行冒号后面的语句,比如:a = 5b = [1, 2, 3]if a not in b: print "hello"这里也能够输出结果hello。
3.Python ,中 while 怎么增加循环的次数 ,比如下方图
i =1
temp = input("不妨猜下我现在心里想哪个数字:")
guess = int(temp)
while guess !=8 and i<3:
if guess == 8:
print("你猜对了")
print("猜中了也没有奖励")
else:
if guess > 8:
print("大了大了")
else:
print("小了小了")
temp = input("重新猜下吧:")
guess = int(temp)
i=i+1
print("游戏结束")
转载请注明出处编程代码网 » pythonwhilenotin