Page 129 - PYTHON-12
P. 129

29.  What is the use of // operator in Python?
           Ans.  It is a Floor Division operator which is used for dividing two operands with the result as quotient, showing
               only digits before the decimal point. For instance, 10//5 = 2 and 10.0//5.0 = 2.0. If one of the operands is
               negative, the output is floored, for example, –10//3 = –4.
            30.  Write two rules to naming an identifier in Python.
           Ans.  (i)  An identifier name must start with a letter or the underscore character.
                (ii)  Identifier name must not be any reserved word or keyword.
            31.  What are literals in Python?
           Ans.  Python literals can be defined as data which can be assigned to a variable or constant. There are 5 types of
               literals available in Python:
                 •  String literals               •  Numeric literals               •  Boolean literals
                 •  Special literals              •  Literal Collections
            32.  Explain Python functions.
           Ans.  A function is a set of instructions or a block of code that is written once and can be called and executed
               whenever required in the program. There are two categories of functions in Python:
                 •  Built-in functions
                 •  User-defined functions
            33.  What are the two types of files in Python?
           Ans.  The two types of files in Python are Text files and Binary files.
            34.  In text file, each line is terminated by which special character?
           Ans.  EOL (End of Line)
            35.  Which command is used to read “n” number of characters from a file using the file object <file>?
           Ans.  read(n)
            36.  What is the difference between actual parameter/argument and formal parameter?
           Ans.  Actual argument/parameter: The values that are passed in a function cell are called actual parameters, e.g.,
               print(sum(3,5)); here 3 and 5 are actual parameters.
               Formal argument/parameter: The variables that are specified in a function definition, e.g., def sum (a, b);
               here a and b are formal parameters.
            37.  Name the different file processing modes supported by Python.
           Ans.  Python provides three modes to work with files:
                 •  Read-only mode                •  Write-only mode                •  Read-Write mode
            38.  What are tell() and seek() functions in Python?
           Ans.  The tell() function returns the current file position of file handle.
                The seek() function is used to change the position of the file handle to a specified position.
            39.  What is the difference between read() and readlines() method?
           Ans.  The read() method reads the entire file and returns in the form of a string.
                The readlines() method reads all the lines and returns each line as list of strings.
            40.  Which mode in file opening statement results or generates an error if the file does not exist?
           Ans.  r+
            41.  Which module is required to use the built-in function dump()?
           Ans.  pickle
            42.  What is/are the basic I/O (input-output) streams in file?
           Ans.  Standard Input, Standard Output and Standard Errors
            43.  What is an operator in Python?
           Ans.  An operator is a particular symbol which is used on some values and produces an output as a result.
                For example, 10 + 30 = 40
                Here, “+” and “=” are operators.
            44.  What are the different types of operators in Python?
           Ans.  Following is a list of operators in Python:
                 •  Arithmetic Operators          •  Relational Operators           •  Assignment Operators
                 •  Logical Operators             •  Membership Operators           •  Identity Operators
          A.24                                                                     Computer Science with Python–XII
   124   125   126   127   128   129   130   131   132   133   134