0% found this document useful (0 votes)
55 views

Python Preparation Questions

Python is an interpreted, object-oriented, high-level programming language created by Guido van Rossum in 1991. It is designed to be highly readable and extensible. Key features of Python include being interpreted, extensible via modules, object-oriented, portable, and having a large standard library. Indentation is syntactically significant in Python and comments can be single-line with # or multi-line within triple quotes.

Uploaded by

nagasanjaysharma
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views

Python Preparation Questions

Python is an interpreted, object-oriented, high-level programming language created by Guido van Rossum in 1991. It is designed to be highly readable and extensible. Key features of Python include being interpreted, extensible via modules, object-oriented, portable, and having a large standard library. Indentation is syntactically significant in Python and comments can be single-line with # or multi-line within triple quotes.

Uploaded by

nagasanjaysharma
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

python

-> created by guido van rossum[dutch] in 1991.

-> What is python?


python is a high level language, which is easy to understand
and it feels like general communication with the system.

-> Advantages of python:


*interpreted
*extensible
*object-oriented
*readability
*free and open source
*portable

->Interpreted:
python is interpreted language. It does not require prior
compilation of code and executes instructions directly.
->extensible:
it is very flexible and extensible with any module
-> object-oriented:
It allows to implement the object oriented concepts to build
application solution.
-> Portable:
it can run without affecting the device performance.

-> What is pep8?


It stands for Python enhancement proposal and its major
task is to improve the readability and consistency of the code.

-> What do you mean by python literals?


literals can be defined as a data which is given in a variable or
constant. python supports
string literal
numeric literal
boolean literal

-> Function:
a fuction is a block of code which is return once and can be
executed whenever reuired in the program. A function has a valid
name, parameter list and body.
ther are two types namely: built in, user defined
-> What type of language is python? programming or scripting?
python is capable of scripting, but in general it is cnsidered as
a general purpose programming language.
-> What is namespace in pythom?
A namespace is a naming system used to make sure that names are
unique to avoid naming conflicts.

-> What is python path?


It is an environment variable which is used when a module is
imported. Whenever a module is imported, python path is also
looked up to check for the presence of the imported modules in
various directories.
-> What are python modules?
python modules are files containing python code. This code can
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
*data time
*Json

-> Python is a case sensitive language.


-> Is identation required in python?
Identation is necessary for python. It specifies a block of code.
all code within loops, classes, functions,etc is specified within
an idented block.
if your code is not idented necessarily, it will not execute
accurately and will throw errors as well.

-> What is the difference between arrays and lists in python


arrays and lists, in python have th same way of storing data. But
arrays can hold only a single data elements whereas lists can hold
any data type elements.

-> What is __init__?


__init__ is a method or constructor in python. This method is
automatically called to allocate memory when a new object/instance
of a class is created.

-> What is lamda function?


an anonymous function is known as a lamda function. This function
can have any number of parameters. But can have just one statement.

-> How does break, continue, and pass work?


Break: Allows loop termination when some condition is met and control
is transfered 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
begining of the loop.
pass: Used when you need some block of code syntatically, but you
want to skip its execution. this is basically a null
operation. NOthing happens when this is executed.

-> What are python iterators?


Iterators are objects which can be traversed through or iterated
upon.

-> How do you write comments in python?


Comments un python start with a #.

-> How to comment multiple lines in python?


Multi-line comments appear in more than one line. All the lines
to be commented are to be prefixed by a #.

-> What are docstrings in python?


docstrings are not actually comments, but they are documentation
strings. These doc strings are within triple Quotes. they are not
assigned to any variable and therfore, at times they serve as
purpose of comments as well.
-> What is pickling and unpickling?
Pickle module accepts any python object and covers it into
a string representation and dumps it into a file by using dump
function, this is called pickling.
the process of retrieving original python objects from the
stored string representation is called unpickling.

-> What is the purpose of is, not an in operators?


is: returns true when 2 operands are true.
not: returns the inverse of the boolean value.
in: checks if some element is present in some.

-> whenever python exits, why isnt all the memory de-allocated?
It is impossible to de-allocate those portions of memory that
are reserved by the C library.
On exit, beacuse of having its own efficient clean up mechanism,
python would try to de-allocate/ destroy every object.
-> What is a dictionary in Python?
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.

-> *args- nothing but arguments, to pass list or tuple of arguments


to function.
-> *kwargs- nothing but argumentd, to pass values of dictionary as
keyword arguments.

-> explain split(), sub(), subn() methods of re module in python?


Split()- uses a regex pattern to split a given string into
list.
Sub()- finds all substrings when it matches and then its
replace with different string.
subn()- Same as sub() but also returns the new string with
no of replacements.

-> What are Python packages?


Python packages are namespaces containing multiple
modules.

-> How can files be detected in python?


To delete a file in python, you need to import the os module
after thet, you need to use the os.remove() function.

-> what are the built in types in python?


- Integers
- Floating point
- Complex numbers
- Strings
- boolean
- Built in functions.

-> How to add values to a python array?


Elements can be used to an array using the append(),
extend() and the insert(i,x) functions.

-> How to remove values to a python array?


array elements can be removed using pop() or remove()
methods. The difference between these two functions
is that the former returns the deleted value whereas
latter does not.

You might also like