Posts

Showing posts from November, 2020

Python3 Tuples DS

Python Data Structures : Tuple  Data Structures : Tuple  Tuples    ->A tuple is similar to list.    ->The difference between the two is that we can't change the elements of the tuple(immutable) once it is assigned whereas in the list, elements can be changed. Tuple Creation : Eg :              #empty tuple        t=( )                #tuple having integers        t=(1,2,3)        print(t)          #tuple with mixed data types        t=(1,'rama',2.5,'a')        print(t)         #nested tuple        t=(1,(1,2),[1,'abc',3])        print(t) output:: (1,2,3)              (1,'rama',2.5,'a')              (1,(1,2),[1,'abc',3])  ...

Python3 Lists DS

Python : Data Structures Data Structure Lists   Data structure:        A data structure is a collection of elements(such as numbers or character-or even other data structures) that is structured in some way, for example, by numbering the elements. The most basic data structure in Python is the "sequence". ->List is one of the sequence data structure ->Lists are collection of items(strings, integers or even other lists) ->Lists are enclosed within [ ] ->Each item in the list has an assigned index value. ->Each item in a list is separated by a comma( , ) ->Lists are mutable, which means they can be changed. List creation : Eg:        emptyList=[ ]        lst=['one', 'two', 'three']            #list of strings        lst2=[1,3,2,4]                            #list of integers     ...

Python3 break and continue Statements

Image
Python break and continue Statements break and continue statements              In Python , break and continue statements can alter the flow of normal loop. Loop iterate over a block of code until test expression is false, but sometimes we wish to terminate the current iteration or even the whole loop without checking test expression.   The break and continue statements are used in these cases. Python Break Statement     Syntax:                 break Flow Chart:                                         Working:                     Eg:        nums=[1,2,3,4]        for num in nums:              if num==4:                 ...

Python3 for Loop

Image
Python For Loop for Loop:         The for loop is used to iterate over a sequence (list, tuple, string) or other iterable objects.      Iterating over a sequence  is called traversal. Syntax:           for element in sequence:                   body of for Here, elements is the variable that takes the value of the item inside the sequence on each iteration. Loop continues until we reach the last item in the sequence. Flow chart:                                        Eg:        lst=[10,20,30,40,50]        product=1        for ele in lst:               product*=ele        print("product is: {}".format(product)) output:: product is: 12000000 for more info : ...

Python3 While loop

Image
Python While Loop   WHILE  Loop :               The while loop in python is used to iterate over a block of code as long as the test expression(condition) is true Syntax::            while test_expression:                 body of while    * The body of the loop is entered only if the test_expression is true.  * After one iteration, the test_expression is checked again.  * This process proceeds until the test_expression is false. Flow Chart : Eg:        lst=[10,20,30,40,50]                product=1        index=0        while index<len(lst):               product*=lst[index]               index+=1        print("Product is:{}".format(product))       ou...

Python3 if..... else

Image
Python if .... else Statement  IF... ELSE STATEMENT :                  The if... elif.. else statements is used in Python for decision making.   if statement syntax:                    if test expression:                                    statement(s) Flow chart :      *  The program evaluates the test expression and execute the statement(s) only if the test expression is true. *  If the test expression is false, the statements is not executed. Eg:          num=25          if num=24:             print("The number is divisible by 2,3,6.")          print(" This will print always.") output:    This will print always. IF.... ELSE STATEMENT :    ...