Viiva Flashcards

1
Q

What are Python Keywords?

A

Keywords are reserved words that convey a specific meaning to the
Python interpreter, and we can use a keyword in our program only for the
purpose for which it has been defined.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Name any 3 Immutable Data Types

A

int, string, tuple

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the difference between a list and a tuple

A

The difference between a list and a tuple is that a list is mutable while a
tuple is not. Tuple can be further implemented as a key to dictionaries.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How can you convert a number into a string?

A

In order to convert a number into a string, use the inbuilt function str(). If
you want an octal or hexadecimal representation, use the inbuilt function
oct() or hex().

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are literals in Python?

A

Python literals can be defined as data which can be assigned to a variable
or constant.
There are five types of literals available in Python:
1. String literals
2. Numeric literals
3. Boolean literals
4. Special literals
5. Literal collections

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is an operator in Python?

A

An operator is a particular symbol that is used on some values and
produces an output as a result.
8. For example,
9. 10+30=40. Here, “+” and “=” are operators

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Why is the return keyword used in Python?

A

The purpose of a function is to receive the inputs and return
some output. The return is a Python statement that we can use in a
function for sending a value back to its calling function or the
operating system.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the difference between the del keyword and clear
() function?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is difference between actual and formal parameter/
arguments.

A

Formal arguments: The formal arguments are the parameters/
arguments in a function declaration.
16. Actual arguments: are values (or variables)/ expressions that
are used inside the parentheses of a function call

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the use of comments in Python?

A

A comment is text that doesnt affect the outcome of a code, it
is just a piece of text to let someone know what you have done in a
program or what is being done in a block of code.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the default sep argument/ parameter for print ()
function

A

The default sep argument for print function is space.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the default end argument/ parameter for print ()
function?

A

The default end argument for print () function is the newline character.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Which loop in python is known as condition loop in
python?

A

While loop

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the extension of binary file in Python

A

.bin or .dat

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Name any two method/ function which are used to write
text file in python

A

write() and writelines()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Which language translator is used by python?

A

Interpreter

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What are the built-in types available in python?

A

Numbers, Strings, Lists, Tuples, Dictionaries

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

How python interpreter interprets the code?

A

Python interpreter interprets the code line by line

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Name a few mutable data types of python.

A

Lists, Sets, and Dictionaries

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Name a few immutable data types of python.

A

Strings, Tuples, Numeric

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What is the significance of a pass statement in python?

A

pass is no operation python statement. This is used where python
requires syntax but logic requires no actions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

. What is slicing in python?

A

Python slicing is a statement of python that extracts a list of elements
from the given sequence in the range of start and stop values with step
value intervals

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

What are comments in python?

A

Python comments are nonexecutable text written in the python
program to give a description for a statement or group of statement

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

How to print list l in reverse order in a single line statement

A

print(l[::-1])

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

Python string can be converted into integer or float?

A

If the string contains only numbers it can be converted into an integer
or float using int() and float() functions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

What is the difference between / and //?

A

/ is used for division, // is used for floor division
o / returns float as answer whereas // returns integer as answer
o / gives you the number with decimal places whereas // gives you only
integer part

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

How to check the variables stored in same object in python?

A

The id() function returns the memory address of python object.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

What are the parameters of print() function? Explain.

A

The print function has three parameters:
 message – Contains the message to be printed
 sep – It is onptional parameter used to print a separator
 end – It prints the endline character

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

What is the significance of ‘else’ in loops in python

A

Else block is written in pyton progrm when loop is not satisfying the
condition. It gets executed when the while loop’s condition is false
where as in for loop it executes when for loop ends normally.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q

Divya is learning python. She wants to know the version of python using
python programming statements. Please help her to accomplish her
task.

A

> > > import sys
o&raquo_space;> sys.version

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
31
Q

How to remove the last element from a list?

A

To remove the last element from a list following ways can be used:
 l.pop()
 del l[-1]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
32
Q

What is the difference between append() and extend() methods?

A

append() is used to add an element to the list to the last.
o extend() is used to add multiple elements to the list.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
33
Q

.Consider the statement: L = [11,22,33,[45,67]], what will be the output
of L[-2+1}?

A

[45.67]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
34
Q

What is tuple unpacking

A

Tuple unpacking refers to extracting tuple values into a separate
variable.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
35
Q

What are the two ways to insert an element into dictionary?

A

Method 1 – Modifying a dictionary with fresh key and value ex.
d={1:’A’,2:’B’}; d[3]=’C’
o Method 2 – With a function setdefault ex.
d={1:’A’,2:’B’};d.setdefault(3,’C’)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
36
Q

Samira wants to remove an element by value. Suggest her a function
name to accomplish her task.

A

l.remove(value)

37
Q

How to remove all elements of a list?

A

There are two ways to remove all elements of list
 Using clear – l.clear()
 Using del – del l

38
Q

How del is different from clear?

A

del removes entire list object where clear() just removes elements and
makes list empty

39
Q

What is a function?

A

A function is a subprogram and a smaller unit of a python program
consists of a set of instructions and returns a value

40
Q

Does every python program must return a value?

A

No, not every python program returns a value

41
Q

What are the parts of a function?

A

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

42
Q

What are the needs of function in the python program?

A

Easy program handling
o Reduce the size of the program
o Reduce the repeated statements
o Ambiguity can be reduced
o Make program more readable and understandable

43
Q

How to call your function through python interactive mode?

A

Save a program if not saved and click on Run > Run Module or press
the F5 button from the python script mode
o Now interactive mode will appear with the message RESTART ……
o Write a function call statement with function name and list of
parameter values in the brackets
o A function call statement is just like a function name with required
parameters
o Press enter and supply input as per requirements

44
Q

What are void functions? Explain with example

A

The void functions are those functions that do not return any value.
o Python function which does not contain any return statement and
having a bunch of different print statements are called void functions.
o Python supports a special object “nothing” or None datatype.

45
Q

.Observe the following lines of code and identify function definition or
function caller statement:
myfun(“TutorialAICSIP”,2020) – function caller with positional
arguments
o myfun(name=”TutorialAICSIP”,year=2020) – function caller with
default arguments
o def myfun(name, year=2020) – function definition with default
argument
o myfun(name=”TutorialAICSIP”,year) – function caller but reaise an
erro

A
46
Q

What are the physical line and logical line structure in python
program?

A

The physical lines in python programs contain EOL (End Of Line)
character at the point of termination of lines
o The logical lines in python programs contain white spaces or tab or
comment at the point of termination of lines

47
Q

What is indentation? Explain its importance in two lines.

A

Indentation refers to white spaces added before each line of the code.
o In python, it detects the block of code.
o It also makes the program more readable and presentable.
o It organizes the code of blocks in a good manner

48
Q

What is a top-level statement in python?

A

The python unindented statements in python programs are considered
as a top-level-statement.
o main is also a python top-level statemen

49
Q

What are the comments? Explain the role of comments in the python
programs?

A

Comments are non-executable parts of python programs.
o You can write a comment for the description or information related to
statements, basic details of programs etc.
o 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 quote

50
Q

Does python program functions contain multiple return statements and
return multiple values?

A

Yes, python program functions can have multiple return statements.
o To return multiple values you can write values with return keyword
separated by comm

51
Q

What do you mean by fruitful and non-fruitful functions in python?

A

The functions which return values are called fruitful functions.
o The function not returning values are called non-fruitful functions.

52
Q

Which three types of functions supported by python?

A

Python supports the following three types of functions:
 Built-in Functions
 Functions defined in modules
 User-defined functions

53
Q

What are parameters and arguments in python programs?

A

Parameters are the values provided at the time of function definition.
For Ex. p,r and n.
o Arguments are the values passed while calling a function. For Ex.
princ_amt, r, n in main().

54
Q

.Which types of arguments supported by Python?

A

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

55
Q

What are the rules you should follow while combining different types of
arguments?

A

An argument list must contain positional arguments followed by any
keyword argument.
o Keyword arguments should be taken from the required arguments
preferably.
o The value of the argument can’t be specified more than once.

56
Q

What do you mean by python variable scope?

A

The python variable scope refers to the access location of the variable
defined in the program.
o A python program structure has different locations to declare and
access the variable.
o There are two scopes of variables in python:
 Local Scope
 Global Scope

57
Q

What is the local and global scope variable?

A

The variable which is declared inside a function and can be accessible
inside a function is known as local variable scope.
o The variable declared in top-level statements of the python program is
called a global variable scope, it is accessible anywhere in the
program.

58
Q

What is the full form of LEGB? Explain in detail.

A

LEGB stands for Local-Enclosing-Global-Buil-in.
o Python checks the order of variable in a program by the LEGB rule.
o 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.

59
Q

What are mutable and immutable arguments/parametersin a function
call?

A

Mutable arguments/parameters values changed over the access of
value and variable at runtime.
o Immutable arguments/parameters whose values cannot be changed.
They allocate new memory whenever the value is changed.

60
Q

What are modules in python?

A

A large program is divided into modules.
o A module is a set of small coding instructions written in a
programming language.
o These modules create a library.
o A python module is a .py that contains statements, classes, objects,
functions, and variables.
o That allows reusing them anytime by importing the module.
o The structure of the python module plays an important role in python
library functions.

61
Q

Name few commonly used libraries in python.

A

o Standard library
o Numpy Library
o Matplotlib
o SciPy

62
Q

What do you mean docstrings in python?

A

Docstrings is the triple quoted text of the python program.
o It provides comments related to the authors of the program, details
about functions, modules, classes.
o The docstrings contents written in the module can be accessed through
help().

63
Q

s there any difference between docstrings and comments?

A

The docstrings and comments ignored by the python interpreter in
execution.
o But the docstring provides the information about modules, functions
or classes which can be accessed by help() function

64
Q

What is the use of dir() function?

A

The dir() function is used to display defined symbols in the modul

65
Q

.What are the two ways to import modules?

A

You can import modules in python using these two ways:
 import <modulename>
 from <module> import <object></object></module></modulename>

66
Q

.What is a file?

A

A file is a stream of bytes stored on secondary storage devices having
an extension.

67
Q

What are the different modes of opening a file?

A

The different modes of opening a file are as follows:
 r,w,a,r+,w+,a+,rb,wb,ab,rb+,wb+,ab+

68
Q

If no mode is specified in open() function, which mode will be
considered?

A

r

69
Q

What is the difference between “w” and “a” mode?

A

“a” mode adds the content to the existing file whereas “w” mode
overwrites the contents into the file.

70
Q

What is the difference between readline() and readlines() function?

A

readline() function reads the content of the text file and returns the
content into the string whereas readlines() function reads the content
of the text file and returns the content into the list.

71
Q

Parth wants to read only n number of characters from a text file.
Suggest him a function to accomplish his task

A

The read(n) function can be used

72
Q

.Nakshatra wants to count no. of words from the text file. Suggest her
code to accomplish a task

A

f=open(“one.txt”)
o w=f.read().split()
o c=0
o for i in w:
 c+=1
 print(c)

73
Q

What are the two different types of text files?

A

Plain text or regular text files
o Delimited text files or separated text files

74
Q

What are full forms of: a) csv b) tsv

A

csv – comma separated values
o tsv – tab-separated values

75
Q

Are CSV files and Text Files same?

A

o CSV files and Text Files are same in storage but csv file stores the
data separated by a delimiter

76
Q

What are the different valid delimiters?

A

, is default delimiter
o other delimiters are tab – \t, colon – :, or semi colon – ;

77
Q

What is pickling?

A

Pickling refers to the process of converting python object hierarchy
into a byte stream to write into a binary file.

78
Q

3.What is unpickling?

A

It is the process of converting the byte stream back into an object
hierarchy.

79
Q

Which module is required to handle binary files?

A

pickle

80
Q

.Name the functions used to read and write data into binary files.

A

pickle.dump(list_object, file_handle)
o pickle.load(file_object)

81
Q

Which error is reported while reading the file binary file?

A

ran out of input

82
Q

How to avoid reading file errors in binary file?

A

By using exception handling with try and except blocks

83
Q

What is the significance of tell() and seek() functions?

A

tell() function returns the current file position in a file
o seek() function change the current file position

84
Q

What is the default value of offset for seek function?

A

0

85
Q

What is offset in the syntax of seek function?

A

Offset refers to the number bytes by which the file object is to be
moved

86
Q

.Nimesh is working on a stack. He started deleting elements and
removed all the elements from the stack. Name this situation

A

Stack underflow

87
Q

What are the operations can be performed on the stack?

A

Push
o Pop
o Peep or Peek

88
Q

Which principle is followed by stack?

A

LIFO (Last in First Out)

89
Q

Name any three applications of stack.

A

Call history on mobile
o Browser history
o Undo and redo commands
o CD/DVD tracks
o Books on the tables