COMPUTER SCIENCE VIVA QUESTION AND ANSWERS
1. Which language translator is used by Python?
A: Interpreter language translator is used by Python.
2. What are the built-in types available in Python?
A: There are four built-in types available in the Python language namely,Numbers, Strings, Lists, Tuples,
Dictionaries.
3. How does a Python interpreter interpret the code?
A: Python interpreter interprets the code line by line in a program.
4. Name a few mutable data types of Python.
A: The mutable data types are Lists, Sets, and Dictionaries in Python Language.
5. Name a few immutable data types of Python.
A: The immutable data types are Strings, Tuples, Numeric in Python Language.
6. What is the significance of a pass statement in Python?
A: Pass statement is no operation Python statement. It is used where Python requires syntax, but logic
requires no actions in a program.
7. What is slicing in Python?
A: Python slicing extracts a list of elements in the range of start and stop values with step intervals from
a sequence.
8. What are the comments in Python?
A: Python comments are non executable text written in the Python program to describe a statement or
group of statements one after the other.
9. How to print list l in reverse order in a single-line statement?
A: In a program print list I reverse can be done like print(l[::-1])
10. Can Python string be converted into an integer or float?
A: If the string contains only numbers, it can be changed into an integer or float using int() and float()
functions.
11. What is the difference between / and //?
A: / is used for division, // is used for floor division, / returns float as answer, // returns integer, / gives
the decimal part, whereas // only gives the integer part
12. How do we check the variables stored in the same object in Python?
A: The id() function allows checking variables in the stored memory address of the Python object.
13. What are the parameters of the print() function? Explain.
A: The print function has three parameters
message – Contains the message to be printed
Sep – It is an optional parameter used to print a separator.
End – It prints the endline character
14. What is the significance of ‘else’ in loops in Python?
A: The other block is written in a Python program when the loop does not satisfy the condition of the
cause. It gets executed when the while loop’s condition is false, in contrast for the for loop, it executes
when the for loop ends.
15. What is the difference between the append() and extend() methods?
A: An Append () is used to add an element to the list to the last. In contrast, the Extend () is used to add
multiple elements to the list.
16. Consider the statement: L = [11,22,33,[45,67]], what will be the output of L[-2+1}?
A: The output will be [45.67] for the statement L = [11,22,33,[45,67]].
17. What is tuple unpacking?
A: Tuple unpacking refers to extracting tuple values into a separate variable in a programming language.
18. What are the two ways to insert an element into a dictionary?
A: There are two ways to insert an element into a dictionary. The ways are stated below:
Method 1: Modifying a dictionary with fresh key and value ex. d={1:’A’,2:’B’}; d[3]=’C’
Method 2: With a function setdefault ex. d={1:’A’,2:’B’};d.setdefault(3,’C’)
19. How to remove all elements of a list?
A: There are two ways to remove all elements of the list.
The elements can be removed from a list using clear – l.clear().
The elements can also be removed from a list using del – del l.
20. How is del different from clear?
The del prompt removes the entire list object where clear() just removes elements and makes the list
empty.
21. What is a function?
A function is a subprogram & a smaller unit of a Python program containing a set of instructions and
returns a value.
22. Does every Python program return a value?
A: No, not every Python program returns a value, some programs are valueless.
23. What are the parts of a function?
A: A Python function has the following parts:
Function header – Function Header starts with the def keyword followed by the function name
and parameters.
Function body – Function body is a block of statements/instructions that define the action
performed by the function; indentation must be followed
Function caller statement – Function caller statement is a writing function name including
parameter values
24. What are the needs of function in the Python program?
A: There are five major needs of function in a python program. The needs are given below.
Easy program handling
Reduce the size of the program.
Reduce the repeated statements.
Ambiguity can be reduced.
Make the program more readable and understandable.
25. How to call the function through Python interactive mode?
A: Students can call the function through the Python interactive mode by the following ways:
Save a program if not saved and click on Run > Run Module or press the F5 button from
the Python script mode.
Now, the interactive mode will appear with the message RESTART ……
Write a function call statement with the function name and list of parameter values in the
brackets.
A function call statement is just like a function name with required parameters.
Press enter and supply input as per requirements.
26. What are void functions? Explain with an example.
A: The void functions are those functions that do not return any value. Python functions which do not
contain any return statement and have a bunch of different print statements are called void
functions.Python supports a particular object, “nothing” or None data type.
27. Observe the following lines of code and identify the function definition or function caller
statement:
my fun(“TutorialAICSIP”,2020)
myfun(name=”TutorialAICSIP”,year=2020)
def myfun(name, year=2020)
my fun(name=”TutorialAICSIP”, year)
A: Students can find the function identity stated below:
my fun(“TutorialAICSIP”,2020) – function caller with positional arguments
myfun(name=”TutorialAICSIP”,year=2020) – function caller with default arguments
def myfun(name, year=2020) – function definition with default argument
my fun(name=”TutorialAICSIP”, year) – function caller but receives an error
28. What are the physical line and logical line structures in the Python program?
A: The physical lines in Python programs contain EOL (End Of Line) characters at the point of
termination of lines. The logical lines in Python programs contain white spaces or tabs or comments at
the point of termination of lines.
29. What is indentation? Explain its importance in two lines.
A: Indentation refers to white spaces added before each line of the code. In Python, it detects the block of
code.It also makes the program more readable and presentable.It reasonably organizes the code of
blocks.
30. What is a top-level statement in Python?
A: The Python unindented statements in Python programs are considered a top-level statement. _main_ is
also a Python top-level statement
31. What are the comments? Explain the role of comments in the Python programs.
A: Comments are non-executable parts of Python programs.Students can write a comment for the
description or information related to statements, basic details of programs, etc.
There are two types of comments:
Single-Line: These comments are written to explain single-line comments, beginning with # Multi-Line:
These comments are written for explaining multi-line comments, begin and end with ”’ triple quotes
32. Do Python program functions contain multiple return statements and return multiple values?
A: Yes, python program functions can have multiple return statements. To return multiple values,
students can write values with the return keyword separated by a comma.
33. What do fruitful and non-fruitful functions mean in Python?
A: The functions that return values are called fruitful functions. The functions not returning values are
called non-fruitful functions.
34. Which three types of functions are supported by Python?
A: Python supports the following three types of functions:
Built-in Functions
Functions defined in modules
User-defined functions
35. What are the parameters and arguments in Python programs?
A: Python program has the following parameters and arguments:
Parameters are the values provided at the time of function definition. For Ex. p,r, and n. Arguments are
the values passed while calling a function for Ex. princ_amt, r, n in main().
36. Which types of arguments are supported by Python?
A: Python supports four argument types:
Positional Arguments: Arguments passed to a function in correct positional order, no. of arguments must
match with no. of parameters required.
Default Arguments: Assign default value to a specific parameter; it is used when the user knows the
value of the parameter; default values are specified in the function header. It is optional in the function
call statement. If not provided in the function call statement, then the default value is considered.
Word Arguments: Keyword arguments are the named arguments with assigned values being passed in the
function call statement; the user can combine any type of argument.
Variable Length Arguments: It allows the user to pass as many arguments as required in the program.
Variable-length arguments are defined with the * symbol.
37. What are the rules one should follow while combining different types of arguments?
A: An argument list must contain positional arguments followed by any keyword argument. Keyword
arguments should be taken from the required arguments, preferably. The value of the argument can’t be
specified more than once.
38. What does Python variable scope mean?
A: The Python variable scope refers to the access location of the variable defined in the program. A
Python program structure has different locations to declare and access the variable. There are two scopes
of variables in Python namely Local Scope and Global Scope
39. What is the local and global scope variable?
A: The variable that is declared inside a function and can be accessible inside a function is known as the
local variable scope. The variable declared in top-level statements of the Python program is called a
global variable scope. It is accessible anywhere in the program.
40. What is the complete form of LEGB? Explain in detail.
A: LEGB stands for Local-Enclosing-Global-Built-in. Python checks the order of variables in a program
by the LEGB rule. First, it checks for the local variable; if the variable is not found locally, then it looks
in enclosing, then global, and then the built-in environment.
41. What are mutable and immutable arguments/parameters in a function call?
A: Mutable arguments/parameter values changed over the access of value and variable at runtime.
Immutable arguments/parameters whose values cannot be changed. They allocate new memory whenever
the value is changed.
42. What are modules in Python?
A: An extensive program is divided into modules. A module is a set of small coding instructions written
in a programming language. These modules create a library. A Python module is a .py that contains
statements, classes, objects, functions, and variables.
That allows reusing them anytime by importing the module. The structure of the Python module plays a
vital role in Python library functions.
43. Name a few commonly used libraries in Python.
A: The most commonly used libraries in Python are as follows:
Standard library
Numpy Library
Matplotlib
SciPy
44. What does docstrings mean in Python?
A: Docstrings in Python programming are the triple quoted text of the Python program. It provides
comments related to the authors of the program and details about functions, modules, and classes. The
docstrings contents written in the module can be accessed through the help().
45. Is there any difference between docstrings and comments?
A: The docstrings and comments were ignored by the Python interpreter in execution. But the docstring
provides the information about modules, functions or classes which can be accessed by the help()
function.
46. What is the use of the dir() function?
A: The dir() function is used to display defined symbols in the module.
###########################################