100% found this document useful (6 votes)
13K views6 pages

Important Computer Science Class 12 Viva Questions

The document discusses important computer science class 12 viva questions related to functions in Python. It covers topics such as the definition of a function, parts of a function, why functions are useful in Python programs, how to call functions, void functions with examples, identifying function definitions versus calls, physical and logical lines in Python, the importance of indentation, top-level statements, comments and their role, multiple return statements and returning multiple values from functions, different types of functions and arguments in Python.

Uploaded by

Pranav Vasudev
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (6 votes)
13K views6 pages

Important Computer Science Class 12 Viva Questions

The document discusses important computer science class 12 viva questions related to functions in Python. It covers topics such as the definition of a function, parts of a function, why functions are useful in Python programs, how to call functions, void functions with examples, identifying function definitions versus calls, physical and logical lines in Python, the importance of indentation, top-level statements, comments and their role, multiple return statements and returning multiple values from functions, different types of functions and arguments in Python.

Uploaded by

Pranav Vasudev
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Important computer science class 12 viva questions

1. What is a function?
○ A function is a subprogram and a smaller unit of a python
program consists of a set of instructions and return a value.
2. Does every python program must return a value?
○ No, not every python program return a value.
3. What are the parts of a function?
○ A python function has the following parts:
■ Function header – Starts with def keyword
followed by function name and parameters
■ Function body – Block of statements/instructions
that define the action performed by the function,
indentation must be followed
■ Function caller statement – writing function
name including parameter values
4. What are the needs of function in the python program?
○ Easy program handling
○ Reduce the size of the program
○ Reduce the repeated statements
○ Ambiguity can be reduced
○ Make program more readable and understandable
5. How to call your function through python interactive mode?
○ Save a program if not saved and click on Run > Run Module
or press the F5 button from the python script mode
○ Now interactive mode will appear with the message
RESTART ……
○ Write a function call statement with 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
6. What are void functions? Explain with example?
○ The void functions are those functions that do not return any
value.
○ Python function which does not contain any return
statement and having a bunch of different print statements
are called void functions.
○ Python supports a special object “nothing” or None
datatype.
7. Observe the following lines of code and identify function
definition or function caller statement:
○ myfun(“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
○ myfun(name=”TutorialAICSIP”,year) – function caller but
reaise an error
8. What are the physical line and logical line structure in python
program?
○ The physical lines in python programs contain EOL (End Of
Line) character at the point of termination of lines
○ The logical lines in python programs contain white spaces
or tab or comment at the point of termination of lines
9. What is indentation? Explain its importance in two lines.
○ 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 organizes the code of blocks in a good manner.
10. What is a top-level statement in python?
○ The python unindented statements in python programs are
considered as a top-level-statement.
○ _main_ is also a python top-level statement
11.What are the comments? Explain the role of comments in the
python programs?
○ Comments are non-executable parts of python programs.
○ You 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 written for
explaining single line comments, begins with #
■ Multi-Line: These comments written for explaining
multi-line comments, begins and ends with ”’ triple
quotes
12. Does python program functions contain multiple return
statements and return multiple values?
○ Yes, python program functions can have multiple return
statements.
○ To return multiple values you can write values with return
keyword separated by comma
13. What do you mean by fruitful and non-fruitful functions in
python?
○ The functions which return values are called fruitful
functions.
○ The function not returning values are called non-fruitful
functions.
14. Which three types of functions supported by python?
○ Python supports the following three types of functions:
■ Built-in Functions
■ Functions defined in modules
■ User-defined functions
15. What are parameters and arguments in python programs?
○ 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().
16. Which types of arguments supported by Python?
○ Python supports three 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 to value to a
certain 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. Default arguments must be
provided from right to left.
■ Key Word Arguments: Keyword arguments are
the named arguments with assigned values being
passed in 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 * symbol.
17. What are the rules you should follow while combining
different types of arguments?
○ 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.
18. What do you mean by python variable scope?
○ 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:
■ Local Scope
■ Global Scope
19. What is the local and global scope variable?
○ The variable which is declared inside a function and can be
accessible inside a function is known as 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.
20. What is the full form of LEGB? Explain in detail.
○ LEGB stands for Local-Enclosing-Global-Buil-in.
○ Python checks the order of variable in a program by the
LEGB rule.
○ First, it checks for the local variable, if the variable not found
in local then it looks in enclosing then global then built-in
environment.
21. What are mutable and immutable arguments/parameters in a
function call?
○ Mutable arguments/parameters 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.
22. What are modules in python?
○ A large 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 an important role
in python library functions.
23. Name few commonly used libraries in python.
○ Standard library
○ Numpy Library
○ Matplotlib
○ SciPy
24. What do you mean docstrings in python?
○ Docstrings is the triple quoted text of the python program.
○ It provides comments related to the authors of the program,
details about functions, modules, classes.
○ The docstrings contents written in the module can be
accessed through help().
25. Is there any difference between docstrings and comments?
○ The docstrings and comments ignored by the python
interpreter in execution.
○ But the docstring provides the information about modules,
functions or classes which can be accessed by help()
function.
26. What is the use of dir() function?
○ The dir() function is used to display defined symbols in the
module.
27. What are the two ways to import modules?
○ You can import modules in python using these two ways:
■ import <modulename>
■ from <module> import <object>

You might also like