• What is the difference between break and continue in Python

    In python, break forces the execution to exit or “break” a for or while conditional loop. The continue statement is used to skip code within a loop for certain iterations of the loop.
    In Python, break and continue statements can alter the flow of a normal loop. Loops 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 cheking test expression. The break and continue statements are used in these cases. break - Jumps out of the closest enclosing loop (past the entire loop statement) continue - Jumps to the top of the closest enclosing loop (to the loop’s header line) break statement: The break statement terminates the loop containing it. Control of the program flows to the statement immediately after the body of the loop. If it is inside a nested loop (loop inside another loop), break will terminate the innermost loop. continue statement: The continue statement is used to skip the rest of the code inside a loop for the current iteration only. Loop does not terminate but continues on with the next iteration.
  • Differences between a list and an array in python

      list
      • A list is a container of objects and can hold elements of different data types
      • Lists are built-in data types in python, so no import is needed to use them
      • A list is flexible and can be changed after its creation.
      • Some arithmetic operations are supported and they are not element-wise
      • An entire list can be printed without a loop
      • A list does not use memory efficiently and is typically slower than an array
      array
      • An array is a container of objects and can hold elements of the same data type only
      • Arrays are not built-in data types in python, so an import is needed to use them
      • Once an array is defined, its size is fixed and cannot be changed
      • All arithmetic operations are supported and are element-wise
      • A loop is needed to print an entire array
      • An array uses memory efficiently and is typically faster than a list
      Though lists and arrays are containers of data and can be indexed and sliced, there are many differences between them:
      A list is a container of objects and can hold elements having different data types.
      An array is a container of objects and can hold elements of the same data type only.
      Lists are built-in data types in python, so no import is needed to use them
      Arrays are not built-in data types in python, so an import is needed to use them
      Not all arithmetic operations are supported and supported ones are not element-wise
      All arithmetic operations are supported and are element-wise
      A list is flexible and can change after its creation. Elements can be added, deleted or modified
      Once the array is defined, the space it occupies in memory, a combination of the number of its elements and the size of each element, is fixed and cannot be changed. The only thing you can do is to create a new array and replace some of its elements by the elements of the original array.
      An entire list can be printed without a loop
      A loop is needed to print an entire array
      A list does not use memory efficiently and is typically slower than an array
      An array uses memory efficiently and is typically faster than a list


    difference-between-list-and-arrayin-python
    gk