if Statements Perhaps the most well-known statement type is the if statement. For example: >>> x = int(raw_input("Please enter an integer: ")) >>> if x < 0: ...(这个地方有空格,否则会报错)x = 0 ... print ’Negative changed to zero’ ...(控制语句这地方不能有空格)elif x == 0: ... print ’Zero’ ... elif x == 1: ... print ’Single’ ... else: ... print ’More’ ... ------------------------------------- >>> def f(x): return x % 2 != 0 and x % 3 != 0 ... >>> filter(f, range(2, 25)) [5, 7, 11, 13, 17, 19, 23] 实验不对
Python学习笔记
最新推荐文章于 2024-09-14 08:25:16 发布