Wednesday, 13 December 2017

Range List Program in Python

Hi All,

See the program



rangelistmain  = range(10)
>>> print(rangelistmain )
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
for number in rangelistmain :
    # Check if number is one of
    # the numbers in the tuple.
    if number in (3, 4, 7, 9):
        # "Break" terminates a for without
        # executing the "else" clause.
        break
    else:
        # "Continue" starts the next iteration
        # of the loop. It's rather useless here,
        # as it's the last statement of the loop.
        continue
else:
    # The "else" clause is optional and is
    # executed only if the loop didn't "break".
    pass # Do nothing

if rangelistmain [1] == 2:
    print("The second item (lists are 0-based) is 2")
elif rangelistmain [1] == 3:
    print("The second item (lists are 0-based) is 3")
else:
    print("Dunno")

while rangelistmain [1] == 1:
    pass

No comments:

Post a Comment