Page 363 - Information_Practice_Fliipbook_Class11
P. 363

19.  What is a dictionary?

             Ans.  A Python dictionary is a collection of key-value pairs. The elements in a dictionary are indexed by keys which
                  must be unique.
              20.  What is the purpose of using update() method with dictionary?
             Ans.  The update() method modifies or updates the dictionary with the elements from another dictionary or from
                  another sequence of key-value pairs.

              21.  Write any one difference between insert() and append() function.
             Ans.  insert() function adds elements at the specified index of list while append() function adds single element at the
                  end of the list.
              22.  What types of tokens are allowed in Python?

             Ans.  The types of tokens are as follows:
                  • Keywords
                  • Identifiers
                  • Literals
                  • Operators
                  • Delimiters
              23.  Can list used as keys in Python dictionaries? Justify your answer.

             Ans.  No,  we  cannot  use  lists  as  keys  of  dictionary  because  lists  are  mutable  and  keys  in  the  dictionary  are
                  immutable.
              24.  What is the difference between else and elif construct of if statement?
             Ans.  The elif construct in an if statement is used to check additional conditions after the initial if condition. If the
                  if condition is not met, the elif condition(s) are evaluated. If any elif condition is met, the corresponding
                  block of code is executed.

                  The else block, on the other hand, is executed when none of the preceding if or elif conditions are met.
                  It is used as a catch-all block to specify what happens when no conditions are true.
              25.  What is purpose of range() function? Give one example.

             Ans.  The range() function generates an iterable sequence using the arguments start, stop and stop of range() function.
                  It is very handy and useful for the 'for' loops, which require an iterable sequence for looping.
              26.  Differentiate between break and continue statements.

             Ans.  break
                  Purpose: Terminates the current loop prematurely.

                  Effect: Exits the loop completely, and the program continues with the next statement after the loop.
                  Typical use case: Used when you want to exit the loop based on a specific condition being met.

                  continue

                  Purpose: Skips the current iteration of the loop.
                    Effect: The loop continues with the next iteration, bypassing any code that follows the continue statement
                  within the current iteration.

                  Typical use case: Used when you want to skip some iterations but continue the loop for others based on a
                  condition.



                                                                                            Viva Voce Questions  349
   358   359   360   361   362   363   364   365   366   367   368