We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 10
rere eee td cee ee eM
* class 13° Teles
VIVA VOCE
|. What is Python?
‘ans. Python isan easy-to-learn, general-purpose, dynamic, interpreted,
programming language. i has efficient high-level data structures an
object-oriented programming,
How can you start Python thraugh Windows command prompt?
Ifyou set the Python path for Windows, then you can start Python with the following:
c> python
‘What is DLE?
IDLE (Interactive Development and Learning Environment) is an environment for developing Python
.") under Windows and other operating systems.
high-level, multi-platform, powerful
1b simple but effective approach to
An
Ans,
programs ("scripts
‘What are the two modes of working in Python?
‘Ans. Python provides two modes of working:
(a) Interactive mode
{b) Script mode
5. Whats a variable?
‘Ans. A variable isan identifer/placeholder that holds a value. In other words, a i
‘computer memory location where the value is stored.
ariable isa reference toa
6, What cana variable hold in Python?
In Python language, a variable can hold a string, a number or several oth
‘class. Variables ean be assigned different values during execution.
ans. er objects such asa function or
7. Name the three key attributes ofan object in Python,
Each object in Python has three key attributes: a type, a value and ani.
8, Define a keyword,
‘A keyword isa reserved word in the Python programming language. Keywords are used to perform a
specific task in a computer program.
9. Why isthe given statement invalid in Python?
wel
‘The statementis invalid because an expression cannotbe placed on thellett ofthe equal’»’sign. Therefore,
ns.
the correct statement should be:
xexed
10, What is Numpy?
NumPy is 2 Python extension module that provides efficient operation on arrays of homogeneous data,
It allows Python to serve asa high-level language for manipulating numerical data tis mainly used to
apply functions on arrays. Major array functions are handled by NumPy. Iis written in Cand Python. It
supports cross-platform,
Ans.
111, What isa NumPy Array?
[A NumPy array is @ multidimensional array of objects of the same type. In memory, itis an object
hich points to a block of memory, keeps track ofthe type of data stored in that memory, how many
dimensions there are, and how large each one is.
12, How is NumPy installed?
‘Ans, NumPy is installed by using the pip, a Python package installer as follows:
tall numpy
Scanned with CamScannerclass 4)% :
33, What is the Ndarray object of NumPy?
‘Ans. The object that is defined in the N-dimensional array type's known as ndarray. The collection of items of
the same typeis described by ndarray and index staring with 0 (zero) is used for accessing the collection
of tems.
14, What are the diferent array attributes of NumPy?
‘Ans, The different array attributes of NumPy are shape, reshape, itemsize, ndim, etc.
5. What are the diferent array creation routines of NumPy?
‘Ans. The array creation routine is used for constructing 2 new ndarray object. Some of the array creation
‘outines are empty), zeros), and ones!)
46, What is the following statement termed as?
abcd=4,2,3,4
‘Ans. Multiple Assignment Statement
117, Name five primitive data types in Python,
‘Ans. Five primitive data types in Python are: Numbers, String, List, Tuple and Dictionary
18. Differentiate between single quotes, double quotes and triple quotes.
‘Ans. The differences are
* Ifyou use single quotes, you do not have to escape double quotes and vice versa,
+ Ifyou use triple quotes, your string can span multiple Fines.
19, Is string @ sequence data type?
Ans. Yes.
20. Define input() method.
‘Ans, The purpose of an input() method is to fetch some information from the user of @ program and store it
Into a variable.
21. What isthe role of a print!) function?
‘Ans. A print() method prints an expression which may be a variabe's value or string ora blank line.
22. What does a print statement add to the end ofthe string?
‘Ans. By default, the print function adds a new line to the end of the string being printed.
23. If you don't use the sep option with print() function, what wil it print?
‘Ans. If sep isnot defined, a space is printed between the values received by the print statement,
24. What isthe default value printed by giving end argument to print() method?
Ans. Anew line (a)
25. What isan operator in Python?
‘Ans. An operator works on data items and performs some mathem:
For example, +, -.*, ,%6,>, <, >=, €,<¢,>>, & |, 4, =, ete
26. When does a logical and operator produce true result?
‘Ans. The logical and operator evaluates to True only if both conditions/operands are true.
al operations or changes the data
27. What is an expression? What does it constitute?
‘Ans. An operand or a combination of operands and operators, when evaluated, yields a single value called
‘an expression. The expression consists of variables, constants and functions.
28. What is modulo operator? Give an example.
Ans The % operator is termed as modulo operator. calculates the remainder of division of one number by
another. For example, 52 shall return the result 36 1—the remainder obtained when we are dividing
Sby2.
29, Which operator is used to compare the values of operands?
e
‘Ans. Relational operator.
Scanned with CamScannerOWE
30.
Ans.
31
Ans.
2,
Ans
33
Ans
34
Ans.
35.
Ans.
36.
. typel) method in Python allows us to know the data type of variable
37.
Ans.
38,
Ans.
39,
a
. Aflow charts a pictor
2.
Ans.
43.
Ans.
Ans.
|. What i iteration construct?
nN
clare 12 recs
——
How can we change the order af evaluation of operator?
We cam use parentheses to alter the order of evaluation of an operator.
What isa unary operator? Give examples.
The operator which requires only ane operand to operate upon Is called unary operator. The + and
‘operators in Python can be used in both binary and unary forms.
n the numeriea ranges in NumPy?
Which functions are available for creating an aay fe
aranget) and linspace'h.
existing axis?
Which fanction is used to join a sequence of arrays along
coneatenstet)
bitlerentiate between binary and ternary operator.
squire only (wo operands to work upon ar
The operators which re« fe binary operators and those which
equite three operands are ternary operators
ween division operator (/) and floor division operator (//).
ifferentate bet
n operator (/) performs integer division on two operands. We get exact division
In Python, the division
‘output, For example,
‘The floor division operator (//) performs an integer division and, asa result, an integer is obtained.
For example,
the fraction part gets truncated.
‘Which function can be used to know the data type of a variable?
[Name the sequence surrounded by either single quotes or double quotes.
string
How can we convert a string into a number in Python?
‘string which contains a number will be converted dato numeric type using int} function
Define a sequence construct.
‘A sequence construct constitutes ail the statements which are executed sequentially.
‘What is selection construct?
A selection construct invalves execution on the basis of certain test conditions.
‘What isa flow chart?
rial/graphical representation of a task. Flow charts are drawn using certain special
‘ovals and circles. These symbols are connected using
purpose symbols such as rectangles, diamonds,
arrows termed as flow lines.
Give an advantage of using 2 flow chart.
Flow chart provides a unique feature of breaking down ofa complex problem nto parts inorder to tain
the solution toa given problem.
Define an infinite loop.
‘An infinite [oop is 2 loop where a condition never becomes false and keeps on executing, It's a never
tending loop, such as a while Ioop in case the situation never resolves toa false value.
Iteration means repetition ofa set of statements until the test condition remains true depending upon
e
the loop,
canned wi amscannerclass y2th Teles .
45. Define the body of the oop
‘ans. the sets of statements which get executed! on the test candition becoming true are defined 25 the body
of the loop.
4G. What ain exit eonttol Hoop? Give an example
oop 1 loop which checks far a consltion to be true o false atthe time of exit from the
ans, An ent conte
oop For example, do aie
87, What s the purpose of using a for loop?
Ans. the for loop 8 used for detinite/Iixed number of erations,
48, What are the supported data types in Python?
Ans, Python has five standard data types
() Numbers
(i) stung
(i) ist
(io) Tuple
{¥) Dictionary
43, 1s Python object-oriented?
Ans, Yes, Python is an Object-oriented Programming language.
'50, What isthe purpose of break statement?
‘Ans. The break statement is used to forcefully terminate the loop execution where it has been given.
1. What isan exception in Python?
[Ang, An error that happens during the execution of the code/program is termed as an exception. For example,
Syntax errors, runtime errors ike division by zero, are examples of exceptions in Python.
‘52. Name the method that works reverse of spit) method in strings.
‘Ans. join() method
53. Define a string
‘Ans. A string isa sequence of characters. Strings are immutable in Python, Le, they cannot be modified once
created.
‘54, Define alist in Python. Why is it mutable and dynamic in nature?
‘Ans. A list in Python Is an ordered collection of items which may belong to any data type. A list is dynamic,
‘mutable type as you can add or delete elements from the list any time.
'55. What happens when an element gets deleted from a list?
‘Ans. When we remove an element from alist, the size or length of thelist decreases by 1 position.
56. What does append() function do?
‘Ans. it simply adds/appends an element to the end of the list.
‘57. What isa dictionary?
‘Ans. A Python dictionary isa collection of key-value pairs. The elements In a dictionary are indexed by keys
which must be unique.
58, What does the item) method of dictionary return?
‘Ans. The item|) method returns a list of dictionary (keyvalue) pars as tuples.
59. Why are Python dictionaries also termed as mappings?
‘Ans. Python dictionaries are called mappings because these are like a collection that allows us to look up for
Information associated with arbitrary keys,
60. Differentiate between hstack and vstack?
‘Ans. hstack is used to stack (join) arrays in sequence horizontally (column
used to stack arrays in sequence vertically (row-wise)
ise). On the other hand, vstack is
Scanned with CamScannerCO OL EE UU
class ys Liles
=
VIVA VOCE
ts of using Python?
objects, modules, threads, exe
that 14 simple and easy, portable,
21, What is Python? What are the bene!
‘Ans. Python is a programming language with jptlons and automatic memory
extensible, built-in data
management, The benefits of Python are
structure and Is open source,
2, What is picking and unpickinn?
‘Ans. Pickle module accepts any Python object and converts it into a string epresentation and dumps it into
wing original Python
J lie by using dump function. This process is called peking, The process of reine
Sbjects from the stored string representation is called unpickling
3, How is Python interpreted?
‘ans. Python language is an interpreted language.
converts the source code that is writen by the programme
Sean translated inte machine language tat as to be executed
4, How is memory managed in Python?
python memory is managed by Python private heap space. All Python object
‘ed in a private heap. The programmer does not have access to this privat
the source code. It
python program runs directly from
which is
10 an intermediate language,
As and data structures are
loca fe heap and the interpreter
takes care of this Python private heap.
«+ Theallocation of Python heap space for Python objects is done by Python memor
[AP ges access to some tools for the programmer to code.
«python also has aninbuilt garbage collector, which recycles allthe unused memory,
and makes it available to the heap space.
ry manager. The core
frees upmemory,
‘5, What isthe difference between ist and tuple?
‘Ans. the difference between list and tuple is that lst is mutable while tuple is not. Tuple can bs
implemented as 2 key to dictionaries.
6. What are the builtin types that Python provides?
stable and immutable types of Python built-in types. Mutable buil-intypes offeredioy Python
3 further
‘Ans, There arem
+ ust
+ Sets
+ Dictionaries
Immutable builtin types are:
* Strings
+ Tuples
+ Numbers
7. What is namespace in Python?
‘Ans, in Python, every name introduced has a place where it lives and can be looked for. This is known as
namespace. Its ike a box where a variable name is mapped to the abject placed. Whenever the variable
is searched, this box willbe searched to get the corresponding object.
8. What is lambda in Python?
‘Ans, Iti a single expression, anonymous function often used as inline function.
9, What is passin Python?
‘Ans. Pass means no-operation Python statement or, in other words, itis a placeholderin compound statement,
‘where there should be a blank left and nothing should be written there.
10, What is slicing in Python?
‘Ans. Amechanism to elect a range of items from sequence typesikelis, tuple, strings etc, is nnown asslicing.
@
Se
anned with CamScannerchess it ' TP/CS
41
Ans.
2.
ans.
23.
Ans,
14
15,
Ans.
16.
Ans.
v7.
Ans.
18.
Ans.
19.
Ans.
20.
2.
Ans.
hats ast hen?
ne jocumenting Python functions,
‘A Python documentation string is known as docstring, It is a way of d
‘modules and classes.
‘What is negative index in Python?
python sequences con be indexed using bath the postive and negative numbers. For pasitve index, is
the fst index, 1is the second index, so on and so forth. For negative index, (-1) is the last index and
(2) the second last index and so on and so forth.
How can you convert a number into a string?
inorder toconvert anumberintoa string, use the inbuilt function st). Ifyou want an octal or hexadecimal
tepresentation, use the inbuilt function act() or hex).
\What do you understand by module and package in Python?
In Python, module is the way to structure a program. Each Python program file is a module which imports
‘other modules lke objects and attributes.
‘The folder of a Python program is a package of modules. A package can have modules or sub-folders.
What are the rules for local and global variables in Python?
Local variables Ifa variable is assigned a new value anywhere within a function's body, itis assumed to
be local.
Global variables: Those variables that are only referenced inside a function are implicitly global.
Explain how to delete a file in Python.
Ale can be deleted by using a command os.remove filename) or 0s.unlink(filename)
Explain how you can generate random numbers in Python.
‘To generate random numbers in Python, you need to import command as:
import random
random.random()
‘This returns a random floating point number in the range
ay
‘What isthe use of // operator in Python?
Itis Floor Division operator which is used for dividing two operands with the result as quotient showing
only dgits before the decimal point. For instance, 10//5 = 2 and 10,0//5.0 = 2.0,
Mention five benefits of using Python.
(2) Python comprises a huge standard library for mos
(6) Python does not require explicit memory management as the interpreter itself allocates memory to
‘new variables and frees them automatically.
{c) Provides easy readability due to the use of square brackets.
() Easy-to-learn for beginners.
(e} Having the built-in data types saves programming time and effort from declaring variables.
Mention the use ofthe split function in Python.
ternet platforms lke email, HTML, etc.
. The use of split function in Python is thatt breaks a string into shorter strings using the defined separator.
It gives a list ofall words present in the string
What are literals in Python?
Python literals can be defined as data which can be assigned toa variable or constant. There are S types
of literal available in Pythor
+ String literals
+ Numeric literals
+ Boolean literals
+ Special iterals
iteral Collections
Scanned with CamScannerth
class 12 thks
22. Explain Python functions
Ans. A function isa set of instructions ora 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
23, Name the diferent file processing modes supported by Pyth
Ans, Python provides three modes to work with files:
+ Read-only mode
+ Writeconly mode
+ Read-Write mode
24, What is an operator in Python?
‘Ans. An operator isa particular symbol which is used on some values and produces an output as result,
For example, 10 + 30= 40
Here, “+” and "=" are operators
25, What are the diferent types of operators in Python?
‘Ans. Following is list of operators in Python:
+ Arithmetic Operators
+ Relational Operators
+ Assignment Operators
+ Logical Operators
+ Membership Operators
+ Identity Operators
+ bitwise Operators
26, What sa Dictionary in Python?
‘Ans, Dictionary isan important built-in datatype in Python. It defines one-to-one relationship between keys
and values Dictionaries contain a par of keys and their corresponding values
Dictionaries are indexed by keys.
27, Whats the use of HELP() and DIR) function in Python?
‘Ans. Both Help() and dlr() functions are accessible from the Python interpreter and used for viewing 3
consolidated collection of buil-n functions.
Help(): The help( function is used to display the documentation steing and also facilitates you to see the
help related to modules, keywords, attributes, etc.
Dir(): The dir() function is used to dspiay the defined symbols.
28. How does Python do compile-time and run-time cade 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 Pythan code will fail only with an
exception when the code execution path does not exist
29, Explain the use of TRY: EXCEPT: RAISE: and FINALLY:
‘Ans. Try, except and finally blocks are used in Python error-handling mechanism. Code is executed in the try
block until an error occurs, Except block is used to receive and handle all errors, Contral is transferred to
the appropriate except block. In all cases, the finally block is executed. Raise may be used to raise your
‘own exceptions
30. What is the purpose of PYTHONPATH environment variable?
‘Ans, PYTHONPATH has a role similar to PATH. This variable tells the Python interpreter where to locate the
‘module files imported into a program. It should include the Python source library directory and the
directories containing Python source code.
@
Scanned with CamScannerClass ixth aves
31, What a
‘Ags. Python has five standard data types
the supported data types in Python?
+ Numbe
+ String
+ ust
= Tuple
+ Dictionary
32, Whats the diference between lists and tuples?
Ans,
sts Tuples
Lists are mutable, Le, they ean be edited | Tuples ave immutable tuples are lists which can'tbe edited)
sts are slower than tuples. Tuples are faster than ist.
Syntax: ‘Synta
List! — 120, ‘python’, 44.5) [tupl = (0, ‘python’, 44.5)
33, How will you reverse alist?
‘Ans, lst.reverse) ~ Reverses items of list in place.
234, What isa string in Python?
‘Ans, A sttng in Python isa sequence of alphanumeric characters. They are immutable abjects. It means that
they don't allow modification once they are assigned a value. Python provides several methods such as,
join(, replace), or spit) to alter strings.
35, Why Is the Return keyword used in Python?
‘Ans, The purpase af 2 function is to receive the inputs and return some output
‘The return isa Python statement which we can use in a function for sending a value back to its calling
function or the operating system.
'36. When should you use the “Break” in Python?
‘Ans. Python provides a break statement to ext from a loop. Whenever the break hits in the code, the control
‘ofthe program immediately exits from the body of the loop. The break statement in a nested loop causes
‘the control to exit from the inne iterative block
37. What isa tuple in Python?
‘Ans. Atupleis collection of type data structure in Python whichisimmutable.Tuples ae similar to sequences,
just lke the lists, However, there are some differences between a tuple and a lst—the former doesn't
allow motifications, the latter does.
‘Also, the tuples use parentheses for enclosing but the lists have square brackets in their syntax.
38, How do you debug a program in Python? Is it possible to step through the Python code?
‘Ans. Yes, we can use the Python debugger (pdb) to debug any Python program. If we start a program using
pdb, then it lets us even step through the code.
39. List down some ofthe POB commands for debugging Python programs,
‘Ans, Here area few PDB commands to start debugging Python code:
‘+ Add breakpoint (6)
+ Resume execution (c)
+ Step-bysten debugging (5)
+ Move to the next line (n)
+ Ut source code (I)
‘+ Print an expression (p)
Scanned with CamScannerClass 12th TPeks
Explain the use of “with” statement
‘Ans. In Python, generally “with” statement is used to open a file, pracess the data present inthe file, and also
to close the file without caling a close() method. “with” statement makes the exception handling simpler
by providing cleanup activites.
General form of with:
with open("ttename”, “mode") as
processing statements
41, How can we display the contents of text le in reverse order?
‘Ans. (a) Convert the given fle into alist.
{b) Reverse the list by using reversed|)
{for in in reversedlis(openi“fle-name”,""))
(2) printine)
42. Differentiate between append{) and extend!) methods
‘ns. Both append{) and extend!) methods are methods of lst. These methods ae used to add elements at the
end of the ist.
+ appendelement) ~ adds the given element at the end of thelist which has called this metho.
+ extens{another-lst)~add the elements of anotherlistatthe endof thelist whichiscalled theextend
method
43, What are the advantages of Python recursion?
‘Ans, Implementing something using Python recursion requires ess effort. The code we write using recursion
willbe comparatively smaller than the code that is implemented by loops. Again, codes that are written
using recursion are easier to understand also
44, What do you understand by Python modules?
‘ns. Afile containing Python definitions and statements s called a Python module. So naturally, the filename
isthe module name which is appended with the sufix py.
45, What do you understand by Python package?
‘Ans. Python package is a collection of modules in directories that gives a package hierarchy. More elaborately,
Python packages are a way of structuring Python's module by using “dotted module names”. So A.B
actually indicates tht 8 is a sub-module which is under a package named A.
46, How can we get current directory using Python?
Ans. To get current drectoryin Python, we need touse os module. Then, we can get the location ofthe current
directory by using getewal) function
47, What isthe diference between del keyword and clear() function?
Ans. The difference between del keyword and clear} functions that while del keyword removes one element
at atime, clear function removes al the elements
- What is primary key?
‘Ans. Primary key isa combination of columns that uniquely identifies a row in a relational table.
49. What is candidate key?
‘ns. All possible combinations of columns thatcan possibly serve as the primary key are called candidate key.
50. What is foreign key?
‘Ans. A combination of columns where values are derived from primary key of some other table is called the
foreign key of the table in which itis contained
51. What is alternate key?
‘Ans. A candidate key that is not serving as a primary key is called an alternate key.
52. What is MYSQL?
‘Ans. MYSQL is an open source RDBMS that relies on SQL for processing the data in the database. The database
's available for free under the terms of General Public License (GPL),
@
canned with CamScannerclass 12
Teles
53, What is ROBMS?
‘Ans. Relational Database Management System (RDGMS) facilitates access, security and integrity of data and
eliminates data redundancy, For example, MYSQL Oracle, Microsoft Sql Server, etc.
54, What is the use of drop command?
‘Ans. Drop command is used to delete tables, For example, Drop Table Orders. Delete commands are used to
delete rows of a table
55. What do you understand by NOT NULL constraint?
‘Ans. This constraint ensures that the null values are not permitted on a specified column, This constraint can
bbe defined at the column level and not at the table level
‘56. What isthe significance of COUNT?
‘Ans. It is used to count the number of values in @ given column or number of rows in a table. For example,
Select count (Roll No.) from students,
57. How can we delete a table in MYSQL?
‘Ans. We can delete a table in MYSQL using the drop command.
‘58. How can we delete a record in MYSQL?
‘Ans. We can delete a record in MYSQL using the delete command.
59, How can we add a record and add a column in a table?
‘Ans. We can add a record by using insert command and we can add a column through the alter table command,
660. Give any two differences between GET and POST submission methods of HTML form,
Ans.
(GET Method POST Method
‘All form data Is encoded into the URL| Form data appears within the message body of the HTTP
appended to the action URL as query | request.
string parameters.
Parameters remain in browser history, | Parameters are not saved in browser history, hence can be
hence cannot be used to send password- | used to send sensitive information.
like sensitive information.
Can be bookmarked. Cannot be bookmarked.
Easier to hack for script Kiddies More difficult to hack
Can be cached. Cannot be cached
61. Give the necessary command to incorporate SQL interface within Python
‘Ans. import MySQtab
62. What is Django?
‘Ans. Django isa high-level Python web framework that encourages rapid development and clean, pragmatic
Gesign. Developed by a fast-moving online news operation, Django was designed to handle two
challenges: the intensive deadlines of @ newsroom and the stringent requirements of the experienced
‘web developers who wrote it.I ets you build high-performing, elegant web applications quickly.
canned with CamScanner