Skip to main content

Featured

Write a Python Program to find palindrome of a given string

If you reverse the word then you get the same word that word is palindrome. def   palindrome ( str ):     pointer =  str       rev_str =  reversed (pointer)       if   list (pointer) ==  list (rev_str):         print ( "It is palindrome" )       else :         print ( "It is not palindrome" )  palindrome( 'level' ) palindrome( 'madam' ) palindrome( 'life' ) palindrome( 'refer' ) Output:  It is palindrome It is palindrome It is not palindrome It is palindrome

Loop control statement

 In order to manage loop we have loop control statement. They allow us to manipulate the flow of loop at a specific point

There are three types of loop statement:

1. Break statement
2. Continue statement
3. Pass 

Break statement:

           In break statement we can end a loop immediately that is the next iteration of loop will not be executed and move out of the loop

num=0
while num<10
   num=num+1
   if num==5:
       break
   print(num)
Print("loop ended")



break statement


Here we have simple counting loop as soon as number reaches the value five the break statement break the loop and executes the rest of the code

Continue statement:

          If we don't want to break the entire loop, only to skip one iteration then we can use the continue statement

num=0
while
        num=num+1
        if num==5:
               continue
       print(num)
print("completed ")



break statement



In this example we always increase number one by one and then print it but if the number is five we skip the iteration so this number doesn't get printed

(In simple it will not end the loop it will skip the particular iteration)

Pass statement:

          It is special statement sincs it does absolutely nothing. It is not a loop control statement but a place holder for code

if num==10:
    pass
else:
   pass


while number<10:
   pass

Sometimes you want to write your basic code structure, without implementing the logic yet. In this case, we can use the pass statement, in order to fill the code blocks. Otherwise, we can’t run the script.



Comments

Popular Posts