# Fibonacci series:
# the sum of two elements defines the next
a, b = 0, 1 #Multiple Assignment
while a < 10: #While loop to be executed till value of a less then 10
print(a)
a, b = b, a+b #Multiple Assignment 2
# the sum of two elements defines the next
a, b = 0, 1 #Multiple Assignment
while a < 10: #While loop to be executed till value of a less then 10
print(a)
a, b = b, a+b #Multiple Assignment 2
Let’s take a look at the above program:
The first line demonstrates multiple assignment where we are assigning value to two variables a and b at the same time with values 0 and 1 respectively. On the last line I have again used multiple assignments, to establish the fact that the expressions on the right-hand side are all first evaluated and then the assignment will take place. Here I shall remind you that the expressions are always evaluated from the left to the right irrespective of the side of expression.
The first line demonstrates multiple assignment where we are assigning value to two variables a and b at the same time with values 0 and 1 respectively. On the last line I have again used multiple assignments, to establish the fact that the expressions on the right-hand side are all first evaluated and then the assignment will take place. Here I shall remind you that the expressions are always evaluated from the left to the right irrespective of the side of expression.
The while loop (also considered as entry control loop as it checks for the validity of the expression based on the condition specified therefore it) executes as long as the condition here: a < 10 is evaluated to true. Python consider any non-zero integer value as true while zero is treated as false.
No comments:
Post a Comment