Viiva Flashcards
What are Python Keywords?
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.
Name any 3 Immutable Data Types
int, string, tuple
What is the difference between a list and a tuple
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 can you convert a number into a string?
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().
What are literals in Python?
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
What is an operator in Python?
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
Why is the return keyword used in Python?
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.
What is the difference between the del keyword and clear
() function?
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.
What is difference between actual and formal parameter/
arguments.
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
What is the use of comments in Python?
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.
What is the default sep argument/ parameter for print ()
function
The default sep argument for print function is space.
What is the default end argument/ parameter for print ()
function?
The default end argument for print () function is the newline character.
Which loop in python is known as condition loop in
python?
While loop
What is the extension of binary file in Python
.bin or .dat
Name any two method/ function which are used to write
text file in python
write() and writelines()
Which language translator is used by python?
Interpreter
What are the built-in types available in python?
Numbers, Strings, Lists, Tuples, Dictionaries
How python interpreter interprets the code?
Python interpreter interprets the code line by line
Name a few mutable data types of python.
Lists, Sets, and Dictionaries
Name a few immutable data types of python.
Strings, Tuples, Numeric
What is the significance of a pass statement in python?
pass is no operation python statement. This is used where python
requires syntax but logic requires no actions
. What is slicing in python?
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
What are comments in python?
Python comments are nonexecutable text written in the python
program to give a description for a statement or group of statement
How to print list l in reverse order in a single line statement
print(l[::-1])
Python string can be converted into integer or float?
If the string contains only numbers it can be converted into an integer
or float using int() and float() functions
What is the difference between / and //?
/ 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 to check the variables stored in same object in python?
The id() function returns the memory address of python object.
What are the parameters of print() function? Explain.
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
What is the significance of ‘else’ in loops in python
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.
Divya is learning python. She wants to know the version of python using
python programming statements. Please help her to accomplish her
task.
> > > import sys
o»_space;> sys.version
How to remove the last element from a list?
To remove the last element from a list following ways can be used:
l.pop()
del l[-1]
What is the difference between append() and extend() methods?
append() is used to add an element to the list to the last.
o extend() is used to add multiple elements to the list.
.Consider the statement: L = [11,22,33,[45,67]], what will be the output
of L[-2+1}?
[45.67]
What is tuple unpacking
Tuple unpacking refers to extracting tuple values into a separate
variable.
What are the two ways to insert an element into dictionary?
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’)