Viva questions for class 12 computer science python with answer
important questions for class 12 computer science (python chapter wise)
1- What is Python?
Ans. Python is a high-level, interpreted, dynamic, Object-Oriented Programming Language that supports GUI programming.
2- Why is Python interpreted?
Ans. Python is interpreted because the program is processed at runtime by the interpreter and you do not need to compile your program before executing it.
3- Who developed Python?
Ans. Python was developed by Guido van Rossum in the early nineties at the National Research Institute for Mathematics in the Netherlands.
4- Why is Python easy to learn?
Ans. Python has relatively few keywords, simple structure and a clearly defined syntax. This allows the student to understand and work easily in a relatively short period of time.
5-Write any one feature of Python library.
Ans. Python library is very portable and cross-platform compatible with UNIX, Windows and Macintosh.
6- Is Python a compiler language or an interpreter language?
Ans. The normal execution of Python program is interpreted. However, subsets of the language can be compiled.
7- Python is a free and open-source language. What do you understand by this feature?
Ans. That Python is a free and open-source language signifies that we do not ave to pay anything to download it. Also, being an open-source language, its source code is also available if we wish to modify it.
8- State some distinguishable features of Python
Ans. Python is a modern, powerful, interpreted language with objects, modules, exceptions (or interrupts) and automatic memory management. It was introduced to the world by Guido van Rossum in the year 1991.
Salient Features of Python are:
(i) Simple and Easy: Python is a simple language that is easy to learn.
(ii) Free/Open source: Anybody can use Python without the need to purchase a licence. High-level Language: Being a high-level language, it can be easily understood by the user without the need to be concerned with low-level details.
(iii)Portable: Python codes are machine and platform-independent.
(iv) Extensible and Embeddable: Python programs support usage of C/C++ codes. pre-written tools for programming,
(v) Standard Library: Python standard library contains
9- What are the two modes to work with python.
Ans: (i) Interactive mode (ii)Script mode
10- What is an expression?
Ans: An expression is legal combination of symbols that represents a value.
11- What is string?
Ans: String is a sequence of characters.
12- What is the use of ‘+’ operator in string?
Ans: ‘+’ operator joins or concatenates the strings on both sides of the operator.
13-What is the use of ‘*’ operator in string?
Ans: ‘*’ operator creates a new string concatenating multiple copies of the same string.
14- How many types of strings are supported in Python?
Ans: Python allows two string types:
i) Single line String- String that terminated in a single line.
ii) Multiline String-String storing multiple lines of text
15- What is a tuple?
Ans: A tuple is an immutable sequence of values which can be of any type and are indexed by an integer.
16- Differentiate between list and tuples.
Ans: Tuples cannot be changed unlike lists, tuples use parentheses, whereas list use square brackets.
You Should also check:
17- What is an argument? Give an example.
Ans: An argument is data passed to a function through function call statement. For example, in the statement print (math.sqrt(25)) the integer 25 is an argument.
18- Python has certain functions that you can readily use without having to write any special code. What types of functions are these?
Ans: The pre-defined functions that are always available for use are known as Python’s built-in functions.
Examples of some built-in functions are: input(), type(), int(), eval(), etc.
19- What is Python module? What is its significance?
Ans: A “module” is a chunk of Python code that exists in its own (.py) file and is intended to be used by Python code outside itself.
Modules allow one to bundle together code in a form in which it can easily be used later. The Modules can be “imported” in other programs so the functions and other definitions in imported modules become available to code that imports them.
20- What is the utility of the built-in function help()?
Ans: Python’s built-in function help() is very useful. When it is provided with a program name or a module-name or a function-name as an argument, it displays the documentation of the argument as help. It also displays the string within its passed-argument’s definition. For example,
>>>help (math)
#TRENDING | |
Chapter-1 Basic Computer Organisation MCQsChapter-2 Types of Software, Operating System MCQsChapter-3 Boolean Algebra, Number System MCQs |
21- What is the difference between local variable and global variable?
Ans:
Local Variable
1- It is a variable which is declared within Function or within a block.
2- It is accessible only within the function /block program.
Global Variable
1- It is a variable which is declared outside all the functions.
2- It is accessible throughout the program in which it is declared.
22- Is return statement optional? Compare and comment on the following two return statements:
Return
return val
The return statement is optional only when the function is void or we can say that when the function does not return a value. A function that returns a value must have at least one return statement. From the given two return statements, the statement:
Return
is not returning any value. Rather, it returns the control to caller along with empty value None. And the statement:
return val
is returning the control to caller along with the value contained in variable val.
23- Distinguish between Java and Python.
Ans: Java and Python can be distinguished on the following bases:
(i) Python programs run slower than the Java codes, but Python saves much time and space. Python programs are 3 to 5 times smaller than Java programs.
(ii)Python is a loosely-typed dynamic language as no time gets wasted in declaring variable types as in Java.
(iii) Python is easier to learn than Java.
24- What is the difference between a keyword and a variable?
Ans. Keyword is a special word that has a special meaning and purpose. For example, int, float, for, if, elif, else, etc., are keywords. Keywords are reserved and are few.
Variable is the user-defined name given to a value. Variables are not fixed/reserved. These are defined by the user but they can have letters, digits and a symbol underscore. They must begin with either a letter or underscore. For example, _age, name, result_1, etc., are the variable names in Python.
25- What is a function? How is it useful?
Ans. A function in Python is a named block of statements within a program.
26- What is the difference between an expression and a statement in Python?
Ans:
S. No. | Expression | Statement |
1 | An expression is a combination of symbols, operators and operands. | Statement is defined as any programming instruction given in Python as per the syntax. |
2 | An expression represents some value. | Statement is given to execute a task. |
3 | The outcome of an expression is always a value. | Statement may or may not return a value as the result. |
4 | For example, 3*7 + 10 is an expression | print (“Hello”) is a statement. |
27- How many kinds of statements are there?
Ans. Statements are categorized into three types:
I) Empty statements,
II) Simple statements, and
III) Compound statements.
28- What is the significance of an empty statement?
Ans. An empty statement does nothing. In Python, an empty statement is a pass statement.
29- Describe flow charts, decision tree and pseudo-code.
Ans. Flow charts are diagrams that show the step-by-step solution to a given problem. A decision tree is a diagrammatic representation of possible outcomes of certain conditions. Pseudo-code is a simple and informal way of writing programming code in English. There are no standard rules to write Pseudo-code.
30- What is the difference between break and continue statements?
Ans. Break and continue are the jump statements, and can be used to alter the flow of loop. Break statement terminates the loop and resumes execution in the statement. Continue statement skips the rest of the code inside a loop for the current iteration.
31- What is the purpose of ‘else’ in a loop?
Ans. Looping statements can have an optional else block as well. The else part is executed if the items in the sequence do not match or when loop gets over.
#TRENDING | |
Chapter-4 Flow of control, conditional statements MCQsChapter-5 For Loop in Python MCQsChapter-6 String & Function in Python MCQs |
32. What is namespace in Python?
Ans: A namespace is a naming system used to make sure that names are unique to avoid naming conflicts.
33. What is PYTHONPATH?
Ans: It is an environment variable which is used when a module is imported. Whenever a module is imported, PYTHONPATH is also looked up to check for the presence of the imported modules in various directories. The interpreter uses it to determine which module to load.
34. What are python modules? Name some commonly used built-in modules in Python?
Ans: Python modules are files containing Python code. This code can either be functions classes or variables. A Python module is a .py file containing executable code.
Some of the commonly used built-in modules are:
- os
- sys
- math
- random
- data time
- JSON
35. Is python case sensitive?
Ans: Yes. Python is a case sensitive language.
36. Is indentation required in python?
Ans: Indentation is necessary for Python. It specifies a block of code. All code within loops, classes, functions, etc is specified within an indented block. It is usually done using four space characters. If your code is not indented necessarily, it will not execute accurately and will throw errors as well.
37. What is the difference between Python Arrays and lists?
Ans: Arrays and lists, in Python, have the same way of storing data. But, arrays can hold only a single data type elements whereas lists can hold any data type elements.
38. What are functions in Python?
Ans: A function is a block of code which is executed only when it is called. To define a Python function, the def keyword is used.
39. How does break, continue and pass work?
Break: Allows loop termination when some condition is met and the control is transferred to the next statement.
Continue: Allows skipping some part of a loop when some specific condition is met and the control is transferred to the beginning of the loop
Pass: Used when you need some block of code syntactically, but you want to skip its execution. This is basically a null operation. Nothing happens when this is executed.
40. How do you write comments in python?
Ans: Comments in Python start with a # character. However, alternatively at times, commenting is done using docstrings(strings enclosed within triple quotes).
41. What is pickling and unpickling?
Ans: Pickle module accepts any Python object and converts it into a string representation and dumps it into a file by using dump function, this process is called pickling. While the process of retrieving original Python objects from the stored string representation is called unpickling.
42. How will you capitalize the first letter of string?
Ans: In Python, the capitalize() method capitalizes the first letter of a string. If the string already consists of a capital letter at the beginning, then, it returns the original string.
43. How will you convert a string to all lowercase?
Ans: To convert a string to lowercase, lower() function can be used.
44. What is the purpose of ‘is’, ‘not’ and ‘in’ operators?
Ans: Operators are special functions. They take one or more values and produce a corresponding result.
is: returns true when 2 operands are true (Example: “a” is ‘a’)
not: returns the inverse of the boolean value
in: checks if some element is present in some sequence
45. What is a dictionary in Python?
Ans: The built-in datatypes in Python is called dictionary. It defines one-to-one relationship between keys and values. Dictionaries contain pair of keys and their corresponding values. Dictionaries are indexed by keys.
46. What are Python packages?
Ans: Python packages are namespaces containing multiple modules.
47. How can files be deleted in Python?
Ans: To delete a file in Python, you need to import the OS Module. After that, you need to use the os.remove() function.
48. What are the built-in types of python?
Ans: Built-in types in Python are as follows –
- Integers
- Floating-point
- Complex numbers
- Strings
- Boolean
- Built-in functions
49. How to add values to a python array?
Ans: Elements can be added to an array using the append(), extend() and the insert (i,x) functions.
50. How to remove values to a python array?
Ans: Array elements can be removed using pop() or remove() method. The difference between these two functions is that the former returns the deleted value whereas the latter does not.
51. What are Python libraries? Name a few of them.
Ans:Python libraries are a collection of Python packages. Some of the majorly used python libraries are – Numpy, Pandas, Matplotlib, Scikit-learn and many more.
52. What is split used for?
Ans:The split() method is used to separate a given string in Python.
53. What is the maximum possible length of an identifier?
Ans: Identifiers can be of any length.
54. What are the common built-in data types in Python?
Ans: The common built in data types in python are-
Numbers– They include integers, floating point numbers, and complex numbers. eg. 1, 7.9,3+4i
List– An ordered sequence of items is called a list. The elements of a list may belong to different data types. Eg. [5,’market’,2.4]
Tuple– It is also an ordered sequence of elements. Unlike lists , tuples are immutable, which means they can’t be changed. Eg. (3,’tool’,1)
String– A sequence of characters is called a string. They are declared within single or double quotes. Eg. “Sana”, ‘She is going to the market’, etc.
Set– Sets are a collection of unique items that are not in order. Eg. {7,6,8}
Dictionary– A dictionary stores values in key and value pairs where each value can be accessed through its key. The order of items is not important. Eg. {1:’apple’,2:’mango}
Boolean– There are 2 boolean values- True and False.
55. What is type conversion in Python?
Ans: Type conversion refers to the conversion of one data type iinto another.
int() – converts any data type into integer type
float() – converts any data type into float type
ord() – converts characters into integer
hex() – converts integers to hexadecimal
oct() – converts integer to octal
tuple() – This function is used to convert to a tuple.
set() – This function returns the type after converting to set.
list() – This function is used to convert any data type to a list type.
dict() – This function is used to convert a tuple of order (key,value) into a dictionary.
str() – Used to convert integer into a string.
complex(real,imag) – This function converts real numbers to complex(real,imag) number.
56. What is slicing in Python?
Ans: Slicing is used to access parts of sequences like lists, tuples, and strings. The syntax of slicing is-[start:end:step]. The step can be omitted as well. When we write [start:end] this returns all the elements of the sequence from the start (inclusive) till the end-1 element. If the start or end element is negative i, it means the ith element from the end. The step indicates the jump or how many elements have to be skipped. Eg. if there is a list- [1,2,3,4,5,6,7,8]. Then [-1:2:2] will return elements starting from the last element till the third element by printing every second element.i.e. [8,6,4].
57. What are Literals in Python and explain about different Literals
Ans: A literal in python source code represents a fixed value for primitive data types. There are 5 types of literals in python-
i) String literals– A string literal is created by assigning some text enclosed in single or double quotes to a variable. To create multiline literals, assign the multiline text enclosed in triple quotes. Eg.name=”Tanya”
ii) A character literal– It is created by assigning a single character enclosed in double quotes. Eg. a=’t’
iii) Numeric literals– They include numeric values that can be either integer, floating point value, or a complex number. Eg. a=50
iv) Boolean literals– These can be 2 values- either True or False.
58. What are negative indexes and why are they used?
Ans: The sequences in Python are indexed and it consists of the positive as well as negative numbers. The numbers that are positive uses ‘0’ that is uses as first index and ‘1’ as the second index and the process goes on like that.
The index for the negative number starts from ‘-1’ that represents the last index in the sequence and ‘-2’ as the penultimate index and the sequence carries forward like the positive number.
The negative index is used to remove any new-line spaces from the string and allow the string to except the last character that is given as S[:-1]. The negative index is also used to show the index to represent the string in correct order.