1.条件表达式
>>> x = 3 >>> x = 1 if x<3 else 2 >>> x 2
2.for语句用于序列类型
<1>通过序列项迭代
>>> List = [‘a‘,‘b‘,‘c‘,‘d‘] >>> for eachList in List: ... print eachList ... a b c d
<2>通过序列索引迭代
>>> for eachList in range(len(List)): ... print List[eachList] ... a b c d
<3>使用项和索引迭代
>>> for i,eachList in enumerate(List): ... print "%d %s" % (i,eachList) ... 0 a 1 b 2 c 3 d
时间: 2024-10-01 03:08:43