Skip to Content

TheBlogReaders.com

Salesforce.com, PHP, MySQL, Javascript, Ajax, Htacces

Python Interview Questions and Answers For Freshers part-1

Be First!

python1. What is Python?
Python is an object oriented and open-source programming language, which supports structured and functional built-in data structures. With a placid and easy-to -understand syntax, Python allows code reuse and modularity of programs. The built-in DS in Python makes it a wonderful option for Rapid Application Development (RAD). The coding language also encourages faster editing, testing and debugging with no compilation steps.

2. What are the standard data types supported by Python?
It supports six data types:
1. Number : object stored as numeric value
2. String : object stored as string
3. Tuple : data stored in the form of sequence of immutable objects
4. Dictionary (dicts): associates one thing to another irrespective of the type of data, most useful container (called hashes in C and Java)
5. List : data stored in the form of a list sequence
6. Set (frozenset): unordered collection of distinct objects

3. Explain built-in sequence types in Python Programming?
It provides two built in sequence types-
1. Mutable Type : objects whose value can be changed after creation, example: sets, items in the list, dictionary
2. Immutable type : objects whose value cannot be changed once created, example: number, Boolean, tuple, string

4. Explain the use of iterator in Python?
Python coding uses Iterator to implement the iterator protocol, which enables traversing trough containers and group of elements like list.The two important methods include _iter_() returning the iterator object and next() method for traversal.

5.Define Python slicing ?
The process of extracting a range of elements from lists, arrays, tuples and custom Python data structures as well. It works on a general start and stop method: slice (start, stop, increment)

6. How can you compare two lists in Python?
We can simply perform it using compare function – cmp(intellipaatlist1, intellipaatlist2)
def cmp(intellipaatlist1, intellipaatlist2):
for val in intellipaatlist1:
if val in intellipaatlist2:
returnTrue
returnFalse

7. What is the use of // operator?
‘//’ is a Floor Divisionoperator, which divides two operands with the result as quotient showing only digits before decimal point.For instance, 6//3 = 2 and 6.0//3.0 = 2.0

8.Define docstring in Python with example.
A string literal occurring as the first statement (like a comment) in any module, class, function or method is referred as docstring in Python. This kind of string becomes the _doc_ special attribute of the object and provides an easy way to document a particular code segment. Most modules do contain docstrings and thus, the functions and classes extracted from the module also consist of docstrings.

9. What function randomizes the items of a list in place?
Using shuffle() function
For instance:
import randomize
lst = [2, 18, 8, 4];
randomize.shuffle(lst)
print “Shuffled list : “, lst
random.shuffle(list)
print “Reshuffled list : “, list

10. List five benefits of using Python?
1. Having the built-in data types, Python saves programmer’s time and effort from declaring variables. It has a powerful dict ionary and polymorphic list for automatic declaration. It also ensures better code reusability
2. Highly accessible and easy-to-learn for beginners and a strong ‘glue’ for advanced Professionals consisting fo several high-level modules and operations not performed by other programming languages.
3. Allows easy readability due to use of square brackets for most functions and indexes
4. Python requires no explicit memory management as the interpreter itself allocates the memory to new variables and free them automatically.
5. Python comprises a huge standard library for most Internet platforms like Email, HTML, FTP and other WWW platforms.

(103)

Previous
Next

Leave a Reply