Page 537 - Computer Science V2.0 Class 11
P. 537

37.  What is the purpose of pass statement in Python?
                  Ans.  In Python, the pass statement is ignored by the interpreter. Thus, it is a dummy statement. Often, it is used to
                      leave a slot for the code to be filled in later. Sometimes, it is also used to simplify program logic when no action
                      is required for a particular condition.

                   38.  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.
                   39.  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.
                   40.  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.

                   41.  What is an infinite loop? Give one example.
                  Ans.  An  infinite  loop  is  the  one  whose  terminating  condition  is  either  missing  or  is  not  reachable.  Thus,  the
                      body-of-the-loop keeps repeating endlessly in an infinite loop.
                   42.  Differentiate between strings and lists.
                  Ans.  The lists and strings are different in following ways:
                      a.  The lists are mutable sequences while strings are immutable.
                      b.   Strings store single type of elements—all characters while lists can store elements belonging to different
                         types.
                   43.  What are nested lists?
                  Ans.  When a list is contained  in another list as a member-element, it is called nested list, e.g., aList = [2, 3, [4, 5]]

                   44.  Can tuples be nested?
                  Ans.  Tuples can contain other compound objects, including list, dictionaries, and other tuples. Hence, tuples can be
                      nested.

                   45.  When would you prefer the tuples over the lists?
                  Ans.  Tuples are preferred over lists when you need an immutable and hashable collection, such as for dictionary
                      keys or as elements in a set. They are also a good choice for representing data structures with a fixed number of
                      items, like coordinates or records, where the data should not change after creation.









                                                                                                 Viva Voce Questions  523
   532   533   534   535   536   537   538   539   540   541   542