Viva Voce
Viva Voce
COMPUTER SCIENCE
BOARD VIVA VOCE QUESTIONS
1. Who developed Python?
Ans. Guido van Rossum, a Dutch programmer, developed Python in 1991.
7. Identify and write the name of the Python module to which the following functions belong:
(a ceil() (b) floor() (c) randint()
)
(d dump() (e) sqrt() (f) Factorial
)
An (a math module (b) math module (c) random
s. ) module
(d pickle module (e) math module (f) math module
)
13. What are the built-in data types that Python provides?
Ans. There are mutable and immutable data types of Python built-in data types. Mutable built-in data types
offered by Python are:
• List
• Sets
• Dictionaries
Immutable built-in types are:
• Strings
• Numbers
18. In file handling, what does the terms ‘r’, ‘a’ stand for?
Ans. ‘r’ stands for read and ‘a’ stands for append.
20. What are the rules for local and global variables in Python?
Ans. Local variables: If a variable is assigned a new value anywhere within a function’s body, it is assumed to be
local.
Global variables: Those variables that are only referenced inside a function are implicitly global.
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.
36. Which mode in file opening statement results or generates an error if the file does not exist?
Ans. r+
43. Which package must be imported in Python to create a database connectivity application?
Ans. mysql.connector
44. Which function will return all rows from the ResultSet in the form of tuple containing records?
Ans. fetchall()
45. Write a statement to import module for MySQL connectivity with Python.
Ans. import mysql.connector
46. In the stack, if a user tries to remove element from the empty stack, what is the situation called?
Ans. Underflow of Stack
47. How does Python do compile-time and run-time code checking?
Ans. In Python, some amount of coding is done at compile-time but most of the checking such as type, name,
etc., is held up until the code execution. Consequently, if the Python code references a user-defined function
that does not exist, the code will compile successfully. The Python code will fail only with an exception when
the code execution path does not exist.
48. Explain the use of try, except, raise and finally blocks.
Ans. The try, except and finally blocks are used in Python error-handling mechanism. Code is executed in the try
block until an error occurs. The except block is used to receive and handle all errors. Control is transferred to
the appropriate except block. In all cases, the finally block is executed. The raise may be used to raise your
own exceptions.
59. To make the changes made by any SQL Queries permanently in database, which function is
used after execution of the query?
Ans. <connectionobject>.commit()
62. Differentiate between file mode ‘w’ and ‘a’ mode with respect to Python.
Ans. ‘w’ mode opens a file for writing only. It overwrites the file if the file exists, otherwise it creates a
new file for writing.
‘a’ mode opens a file for appending at the end of the existing file, otherwise it creates a new file for writing.
63. What is the difference between del keyword and clear() function?
Ans. The difference between del keyword and clear() function is that while del keyword removes one
element at a time, clear function removes all the elements.
64. Give the syntax of seek() method while working randomly with Python Files.
Ans. file_object.seek(offset[,reference_point])
85. Give the necessary command to incorporate SQL interface within Python.
Ans. import MySQLdb
86. To establish a connection between Python and SQL database, connect() is used. Which argument(s)
may not necessarily be given while calling connect()?
Ans. database name
87. Which of the functions gives the result as a string when applied while reading contents from a
text file in Python?
Ans. read() and readline()
88. After executing any DML command from Python in Python-MySQL connectivity, which
method/statement is necessary to execute in order to make the changes permanent in MySQL?
Ans. commit()
89. Which function is used to open a connection with MySQL database from within Python using
mysql.connector package?
Ans. connect()
90. After establishing database connection, which database object is created so that the SQL query
may be executed through it to obtain result set?
Ans. cursor