This gives you a better representation. If you are tight on space, then you can store it as either of the following:
or
python interview questions :72
Converting a Python dict to Octave equivalent?
python interview questions :73
How to retrieve data from a table in MySQL database through Python code?
import MySQLdb module as : import MySQLdb
establish a connection to the database.
initialize the cursor variable upon the established connection: c1 = db.cursor()
retrieve the information by defining a required query string. s = “Select * from dept”
fetch the data using fetch() methods and print it. data = c1.fetch(s)
close the database connection. db.close()
python interview questions :74
Explain about ODBC and Python ?
ODBC (“Open Database Connectivity) API standard allows the connections with any database that supports the interface, such as PostgreSQL database or Microsoft Access in a transparent manner
There are 3 ODBC modules for Python:
PythonWin ODBC module - limited development
mxODBC - commercial product
pyodbc - it is an open source Python package.
python interview questions :75
How would you define a protected member in a Python class?
All the members of a class in Python are public by default. You don’t need to define an access specifier for members of class.
By adding ‘_’ as a prefix to the member of a class, by convetion you are telling others please don’t this object, if you are not a subclass the respective class.
python interview questions :76
How do you remove duplicates from a list?
sort the list
scan the list from the end.
while scanning from right-to-left, delete all the duplicate elements from the list
python interview questions :77
Differentiate between append() and extend() methods. ?
Both append() and extend() methods are the methods of list. These methods a re used to add the elements at the end of the list.
append(element) - adds the given element at the end of the list which has called this method.
extend(another-list) - adds the elements of another-list at the end of the list which is called the extend method.
python interview questions :78
Name few Python Web Frameworks for developing web applications?
There are various web frameworks provided by Python. They are
web2py - it is the simplest of all the web frameworks used for developing web applications.
cherryPy - it is a Python-based Object oriented Web framework.
Flask - it is a Python-based micro-framework for designing and developing web applications.
python interview questions :79
How do you check the file existence and their types in Python?
os.path.exists() - use this method to check for the existence of a file. It returns True if the file exists, false otherwise. Eg: import os; os.path.exists(‘/etc/hosts’)
os.path.isfile() - this method is used to check whether the give path references a file or not. It returns True if the path references to a file, else it returns false. Eg: import os; os.path.isfile(‘/etc/hosts’)
os.path.isdir() - this method is used to check whether the give path references a directory or not. It returns True if the path references to a directory, else it returns false. Eg: import os; os.path.isfile(‘/etc/hosts’)
os.path.getsize() - returns the size of the given file
os.path.getmtime() - returns the timestamp of the given path.
python interview questions :80
Name few methods that are used to implement Functionally Oriented Programming in Python?
Python supports methods (called iterators in Python3), such as filter(), map(), and reduce(), that are very useful when you need to iterate over the items in a list, create a dictionary, or extract a subset of a list.
filter() - enables you to extract a subset of values based on conditional logic.
map() - it is a built-in function that applies the function to each item in an iterable.
reduce() - repeatedly performs a pair-wise reduction on a sequence until a single value is computed.
The list1 and list3 are hence operating on the same default list, whereas list2 is running on a separate list that it has created on its own (by passing an empty list as the value of the list parameter).
The definition of the extendList function can get changed in the following manner.
With this revised implementation, the output would be:
Related Searches to Python django interview questions
object oriented programming python for beginnerspython object oriented programming exercisespython object oriented programming pdfpython remove duplicates from list keep orderpython remove duplicates from list of listspython remove duplicates from stringpython remove duplicates from list of dictionariesremoving all the duplicate elements in a list in pythonpython extend returns nonepython list extend vs +append list to a list python