Page 46 - PYTHON-11
P. 46

43.  What are binary operators? Give examples.
             Ans.  Binary operators are those operators that work with two operands. For example, a common binary
                 expression would be x + y, the addition operator (+) surrounded by two operands. Binary operators are
                 further subdivided into arithmetic, relational, logical and assignment operators.
              44.  Differentiate between division operator (/) and floor division operator (//).
             Ans.  In Python, the division operator (/) performs a division operation on two operands and returns the quotient.
                 For example,
                 >>> 5/2
                 2.5
                  The floor division (//) performs an integer division and, as a result, an integer value is obtained.
                  For example,
                 >>> 8//3
                 2
                  Here, the fraction part gets truncated.
              45.  Define membership operators in Python with examples.
             Ans.  We use membership operators to check whether a value or variable exists in a sequence (string, list, tuples,
                 sets, dictionary) or not.
                  For example, the statements:
                 >>> x = "Hello, World!"
                 >>>print("hello" in x)
                     False                        #Output
                     OR
                 >>>x = "Hello, World!"
                 >>>print("hello" not in x)
                     True                         #Output
              46.  Which function can be used to know the data type of a variable?
             Ans.  type() method in Python allows us to know the data type of a variable.
                  For example,
                 >>>c=9.8
                 >>>type(c)
                    <class 'float'>
              47.  What is the significance of using break statement?
             Ans.  In Python, break is a loop control statement. It is used to control the sequence of the loop. Suppose you
                 want to terminate a loop and skip to the next code after the loop; break will help you do that.
                  For example,
                 x=int(input("enter a number"))
                 for i in range (10):
                     if x<10:
                         print(i)
                     elif x>10:
                         break
              48.  Name the sequence surrounded by either single quotes or double quotes.
             Ans.  String.
              49.  How can we convert a string to a number in Python?
             Ans.  A string which contains number will be converted to numeric type using int() function.
              50.  Define a sequence construct.
             Ans.  A sequence construct constitutes all the statements which are executed sequentially.
              51.  What is selection construct?
             Ans.  A selection construct involves execution on the basis of certain test conditions.
              52.  Define an infinite loop.
             Ans.  An infinite loop is a loop where a condition never becomes false and keeps on executing. It is a
                 never-ending loop, such as a while loop in case the situation never resolves to a False value.
                  For example,
                 while True:
                      print("This is an infinite loop!")


                                                               V.4
   41   42   43   44   45   46   47   48   49   50   51