Python Interview Questions for freshers

If anybody searching for python interview questions for freshers then this is the page we can provide all type selective questions. Top 30 questions here cited with real-time examples. So just review before going for python face to face interview.



What is the difference between Java and Python?

Python.

  1. It is faster than java in terms of performance.
  2. Dynamically typed
  3. Not compatible with any platform.
  4. Database access is weaker than java
  5. Indentation does by only new line.

Java.

  1. It is a bit slower than Python in performance-wise.
  2. Static typed
  3. Compatible to all Platform.
  4. Database access is Good in Java.
  5. Indentation does by braces.

What is the difference between list and tuples in Python?

List



  1. Lists are mutable
  2. List can be edited
  3. Syntax of the list is shown by [] bracket.
  4. Syntax: list_1 = [5, ‘Kumar’, 20]

tuples

  1. Tuples are immutable
  2. Tuples are a list but then can’t be edited
  3. Syntax of tuples is shown by parenthesis.
  4. Syntax: tup_1 = (5, ‘Kumar’ , 20)

Write Python logic to count the number of capital letters in a file.

 

How to make Indentation in Python

Unlike language like C, C++, Java It has some different Indentation mechanism.
Other languages follow the indentation like braces or semicolon, where are Python followed by the new line. In order to code readable Programmer must have to make Indentation.
The syntax for example of Indentations

 



What is the difference between .py and .pyc files?

Python compiles the .py and saves files as .pyc
In Simple we can say .py files are Python source files.  where as .pyc files are the compiled bytecode.
Once the *.pyc file is generated, there is no need of *.py file, unless until you edit the .py  file. So it will save your time, No need to compile again an again.

What is the difference between *var and  ** var in Python?

Both  *var and ** var allow you a pass a variable to the number of argument to functions.

Here *var or **var you can change like anything. eg- *kar, **kar (take for your convenience)



*var is used to send a non-keyworded variable-length argument list to the function.

 

**var allows you to pass a keyworded variable length of arguments to a function.

 

What are the Python Web Frameworks for developing web applications?

There are some web frameworks provided by Python. They follow below
TurboGears –  It permits you to quickly develop protractile data-driven Web applications.
Bottle – It is a micro-framework for developing the web application.
web2py – it is the simplest of all the web frameworks used for developing web applications.
cherryPy – it is a Python-based Object based Web framework.
Flask – it is  a micro-framework for developing and designing web applications.
Sanic– It is a Python web framework built on uvloop (event loop) which is made for fast HTTP responses.



Explain Some in-built functions to manipulate list in Python!

Compares elements of both lists – cmp(list1, list2)

Get the length of the list – len(list)

Get the max value from a list – max(list)



Get the min value from a list –min(list)

Get the lowest index in the list that object appears – list.index(obj)

Inserts object obj into list at offset index –list.insert(index, obj)



Removes and returns last object or obj from list – list.pop(obj=list[-1])

Removes object obj from list- list.remove(obj)

Reverses objects of list in place- list.reverse()



Sorts objects of list, use compare func if given – list.sort([func])

What is the usage of help() and dir() function in Python?

help() is a useful  default function in Python program that can be used to get the documentation of a particular object, method, attributes, etc.

 

In Python to get all the attributes list we you have to use dir() function, where you need to pass the argument as an object. If you won’t passes any argument then it will return list of a current local namespace.

 



OutPut : You will get all default local names space like [‘__add__’, ‘__class__’,…]

What are uses of  “/” and “//” operator in python?

Division(“/”): Divides left hand operand by right hand operand.

Here This work like general mathematics way.  suppose

Floor Division(“//”): The division of operands where the result is the quotient in which the digits after the decimal point are removed. But if one of the operands is negative, the result is floored, i.e., rounded away from zero (towards negative infinity).

 



What is a dictionary in Python?

In Python Dictionary defines one-to-one relationship between keys and values. Dictionaries contain a pair of keys and their corresponding values. Dictionaries are indexed by keys like JSON data or associative array.Let’s have a simple example for the sake of understanding.

 

Differentiate between append() and extend() methods in Python ?

append() and extend() methods are the methods of list in Python. These methods are used to a dd the elements at the end of the list.
append(element) – adds the given element at the end of the list.
extend(another-list) – adds the elements of another-list at the end of the list.

What is a monkey patch?

In Simple you can say, monkey patching is changes can done to a module or a  class while the program is running.

 



What is lambda in python and how it used?

In Python functions are defined by using def keyword before function name, If the function having no name means anonymous function then python used lambda before it.

 

What is docstring in Python?

docstrings provide a way of associating documentation with Python functions, classes, methods and modules.
It Unlike commenting in Source Code other languages C, C++, JAVA, PHP etc. The docstring line should begin with a capital letter and end with a period.

What is TkInter?

TkInter is a toolkit for GUI development. It provides support for various  controls for GUI tools  such as text boxes, radio buttons, labels, buttons etc. The common attributes of them include  Colors, Fonts, Cursors, Dimensions etc.



What are list of database access by python?

Python Database API supports Wide range of database server

  • mSQL
  • MySQL
  • PostgreSQL
  • Microsoft SQL Server 2000
  • Informix
  • Interbase
  • Oracle
  • Sybase
  • GadFly

How Could you send an Email Using Python program?

Generally, SMTP is controlled by sending e-mail and routing e-mail between mail servers in other languages.But here Python provides smtplib module, which defines an SMTP client session object that can be used to send mail to any Internet machine with an SMTP or ESMTP listener daemon.

Example-



#!/usr/bin/python

What is Pickling in Python?

Pickling is alternatively called as serialization. It serializes Python object to byte stream stored in a file format. Again byte stream can be converted to object by unpickling.

How many types of sequences are supported by Python?

Python supports 7 sequence types. They are like unicode, xrange, str, list, tuple, byte array and buffer. where xrange is deprecated in python 3.5.X.



Advertisements