Page 102 - PYTHON-12
P. 102
25. 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.
26. Write any two rules of 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.
27. What are literals in Python?
Ans. Python literals are fixed numeric or non-numeric value which can be defined as number, text or other data
which can be assigned to a variable or constant. For example: 30,–8.97,”Learning”, etc.
There are 5 types of literal available in Python:
• String literals • Numeric literals • Boolean literals
• Special literals • Collection literals
28. 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
29. What are the three types of files in Python?
Ans. The three types of files in Python are Text files, Binary files and CSV files.
30. In text file, each line is terminated by which special character?
Ans. EOL (End of Line)
31. Which command is used to read “n” number of characters from a file using the file object <file>?
Ans. read(n)
32. 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.
33. 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
34. 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.
35. 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.
36. Which mode in file opening statement results or generates an error if the file does not exist?
Ans. r+
37. Which module is required to use the built-in function dump()?
Ans. pickle
38. What is/are the basic I/O (input-output) streams in file?
Ans. Standard Input, Standard Output and Standard Errors
39. 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.
A.30 Computer Science with Python–XII