Posts

Showing posts with the label python

While loop in Python

Here we take i =0 and checks every time with some increment value and we should have a check condition that the while loop checks whether value of i satisfies it or not.The loop runs until the condition is true and loop breaks when condition is false. i=0 while (i<6):     print(i)     i+=3 Answer: 0 3  In this example we incremented at the rate of 3 , for the first time i=0 increment value is 3 so i =0+3 then for the next iteration i=3 and later i=3+3 = 6 so the condition fails. Loop breaks that is how while loop works in python

For Loop in Python

For loop has very significant role in any programming language so as in python. Here we see some of the examples of for loop in python... For loop in Python: for x in range(0,5):       print(x)  Here for every iteration i.e. starting from 0 to 4 it prints the value of x Answer: 0 1 2 3 4 Let us take   name = "techuplift" for x in name:       print(x)  Answer: t e c h u p l i f t fruits=["apple","banana","citrus"] for x in fruits:       print(x)  Answer: apple banana citrus examples too be continued...