Python Interview Questions And Answers

H2Kinfosys
H2Kinfosys Education & Training

A for loop is probably the most common type of loop in Python. A for loop will select items from any iterable. In Python an iterable is any container (list, tuple, set, dictionary), as well as many other important objects such as generator function, generator expressions, the results of builtin functions such as filter, map, range and many other items.

Job Oriented || Instructor Led ||
Face2Face True Live I.T Training for
Everyone
Python Interview questions and Answers
1. How do you make a loop in Python 3?
There are 3 main ways to make a loop (or a loop like) construct:
While
A while loop is the simplest type of loop, where the body of the loop is repeated until a
condition becomes False
1. even =True
2. while even:
3. num=input('Provide an even integer > ')
4. even =(int(num)%2==0)
For loop
A for loop is probably the most common type of loop in Python. A for loop will select items
from any iterable. In Python an iterable is any container (list, tuple, set, dictionary), as well
as many other important objects such as generator function, generator expressions, the
results of builtin functions such as filter, map, range and many other items.
An example of a for loop :
1. the_list=[1,2,3,4,5,6,7,8,9]
2. for item inthe_list:
3. print(item, item**2)
Comprehensions
Comprehensions are a loop like construct for use in building lists, sets and dictionaries
A list comprehension example :
1. # Build the list [0,2,4,6,8,10]
2. my_list=[x for x inrange(11)if x%2==0]
2. What is the difference between pop() and remove() in a list in
Python?
pop() takes an index as its argument and will remove the element at that index. If no
argument is specified, pop() will remove the last element. pop()also returns the element it
removed.
remove() takes an element as its argument and removes it if it’s in the list, otherwise an
exception will be thrown.
1. mylist=['zero','one','two','three']
2.
3. print(mylist.pop())# removes last element
4. print(mylist.pop(1))# removes a specific element
5. mylist.remove('zero')# removes an element by name
6. print(mylist)
7. mylist.remove('foo')# ...and throws an exception if not in list
3. Python (programming language). How do you check if a given key
already exists in a dictionary?
use the ‘in’ operator for a simple membership test, but in some cases, a call to the get
method might be better.
Using get to retrieve a value if it exists, and a default value if it doesn’t
for example:
val=my_dict.get(key,None)
Using ‘in’ to decide which operation is needed :
If you are testing for an existing key, and wondering whether to insert or append - there is
another thing you can do: if you have code like this :
1. if key inmy_dict:
2. my_dict[key].append(value)
3. else:
4. my_dict[key]=[]
4. What does * and ** means in Python? Is it to do with pointers and
addresses?
There are a number of uses of * and ** :
 * is the multiplication operator (or in the case of strings a repetition operator).
Classes in other libraries may use ‘*’ for other reasons, but nearly always it is
multiplication in some form.
 ** is an exponent operator such that in normal numbers x ** y is the mathematical
method for computing xyxy
5. What's the purpose of __main__ in python? How it is used and when?
For every module that is loaded/imported into a Python program, Python assigns a special
attribute called __name__.
The rules for how __name__ is set are not that complex :
 If the module is the first module being executed, then __name__ is set to ‘__main__’
 If the module is imported in some way, then __name__ is set to the name of the
module.
6. Why are lambdas useful in Python? What is an example that shows
such usefulness if any?
An example of the use case for lambdas is doing sorts, or map, or filter or reduce.
For example to remove odd numbers from a list:
1. evens_only=list(filter(lambda x:x %2==0, numbers))
So here the filter takes a function which needs to return true for every value to be contained
in the new iterable.
To sort a list of tuples, using only the 2nd item in the tuple as the sort item:
1. sorted=sorted(un_sorted_list_of_tuples, key=lambda x: x[1])
Without the key the sorted function will sort based on the entire tuple (which will compare
both the 1st and 2nd items). The sort method on lists works similarly if you want to sort in
place.
Using reduce to multiply a list of values together
2. product =reduce(lambdax,y: x*y,list_of_numbers,1)
Here reduce expects a function (such as a lambda) that takes two values and will return
one).
Another use case is for map to apply a transformation to every entry in a sequence - for
instance:
1. fromitertoolsimport count
2. for square inmap(lambda x:x*x, count()):
3. print(square):
4. if square >100:
5. break
This code uses map to generate a sequence of square numbers up to but not greater than
100.
Itertools.count is a great function that produces a sequence of numbers starting from 1 and
never ending ( similar to range but without an end).
7. How do you randomly select an item from a list in Python?
You can achieve this easily using choice method from random module
1. import random
2. l =[1,2,3,4,5]
3. selected =random.choice(l)
4. print(selected)
An alternative method would be selecting a random index
using random.randint. But random.choice is more convenient for this purpose.
8. What are Python modules?
A module is a collection is functions, classes and data which together provide related set of
functionality. For instance you could have a module which implements the http protocol,
and another module which create jpeg files. To make use of a module, and the functionality
in it - a python program simply has to import it.
You also find the Python has packages - A package is a set of modules - which are related - to
each other; An example would be the Django package. You have a set of modules which
define models, and another which supports web forms, another which supports views,
another which supports data validation and so on. They all relate to each to to provide the
Django package of functionality for writing web servers.
9. What are the differences between tuples and lists in Python?
The main difference:
 lists can be changed once created - you can append, and delete elements from the
list, and change individual elements - they are mutable.
 tuple, once created, cannot be changed - you cannot append or delete elements
from a tuple, or change individual elements - they are immutable.
10. Why would you want a data structure that can’t be changed once
created?
 Tuples are smaller in terms of memory used than a list with the same number and
type of elements.
 Tuples are ideally suited for data where the order of elements is well understood
by convention - for instance co-ordinates (x,y,z), colours (RGB or HSV). If you
need a tuple type structure but with named elements, not index numbers, then
you can use the NamedTuple type.
 In general, a tuple can be stored in a set, or form the key for a dictionary - whereas
as a list cannot be. In python terms it is hashable. (Although you can make tuples
un-hashable by choosing the wrong data types).
11. What do 'write', 'read' and 'append' signify in Python's open()
function?
Write, read and append are what are termed the access mode. They indicate what the
intended operation on the file will be.
They have two important effects:
1. They relate directly to the permissions on a file - All O/S implement in some form
the idea of read write permission on a file. Attempting to open a file for writing or
appending that the program doesn’t have permission to write to, or opening a file
for reading that the program doesn’t have permission to read is by definition an
error, and in Python will raise an exception - specifically PermissionError.
2. They directly relate to how the file is opened, and where the file pointer is set to
(the O/S will maintain a file pointer which is where in the file the next read or
write will occur - it is normally a count from zero of the number of bytes in the
file.):
 read : The file is opened with the file pointer set to zero - i.e. read from the start of
the file.
 write : The file is opened, the file length is set to zero, and the file pointer is set to
zero - i.e. write from the start of the file ignoring all previous contents
 append : The file is opened, the file pointer is set to the end of the file - i.e. write from
the end of the file, retaining all previous contents.
12. How do I write a program about summing the digits of a number
in Python?
The answers so far do this numerically, which is perfectly fine, but I think it’s more Pythonic
to consider the number as a string of digits, and iterate through it:
1. >>>num=123456789
2. >>>sum_of_digits=0
3. >>>for digit in str(num):
4. ...sum_of_digits+=int(digit)
5. ...
6. >>>sum_of_digits
7. 45
A more advanced solution would eschew the loop and use a generator expression. There’s
still a loop in there, but sum_of_digits is computed all in one go, so we don’t have to set it to
0 first:
1. >>>num=123456789
2. >>>sum_of_digits= sum(int(digit)for digit in str(num))
3. >>>sum_of_digits
4. 45
13. What is “_init_” in Python?
__init__ (double underscore “init” followed by double underscore), when it’s used as the
name of a method for a class in Python, is an instance “initialization” function.
In Python most (almost all) of the “special” class methods and other attributes are wrapped
in “double underscore” characters. Theare, sometimes referred to as “dunder” methods (or
attributes).
14. Why do python classes always require a self parameter?
I will explain this with an example.
I have created here a class Human which I’m defining with Self.
Here I have created the object, Will.
1. classHuman():
2.
3. def __init__(self,name,gender):
4.
5. self.name = name
6. self.gender= gender
7.
8. defspeak_name(self):// the self-going to speak the name
9. print MY NameisWill%self.name
10.
11. will =Human("William","Male")
12.
13. print will.name
14. printwill.gender
15.
16. will.speak_name()
So, self-represents the object itself. The Object is will.
Then I have defined a method speak_name. ( A method is different from Function because it
is part of the class) It can be called from the object. Self is an object when you call self, it
refers to will.
This is how self-works.
Whenever you use self. something, actually you’re assigning new value or variable to the
object which can be accessed by the python program everywhere.
15. In Python, what is NumPy? How is it used?
Python NumPy is cross platform & BSD licensed. You often used it with packages like
Matplotlib & SciPy. This can be an alternative to MATLAB. Numpy is a portmanteau of the
words NUMerical and Python.
Features of Numpy-
 NumPy stands on CPython, a non optimizing bytecode interpreter.
 Multidimensional arrays.
 Functions & operators for these arrays
 Python alternatives to MATLAB.
 ndarray- n-dimensional arrays.
 Fourier transforms & shapes manipulation.
 Linear algebra & random number generation.
Register & post msgs in Forums:http://h2kinfosys.com/forums/
Like us on FACE BOOK
http://www.facebook.com/H2KInfosysLLC
Videos : http://www.youtube.com/user/h2kinfosys

Recomendados

Python interview questions and answers por
Python interview questions and answersPython interview questions and answers
Python interview questions and answersRojaPriya
149 visualizações25 slides
Python interview questions por
Python interview questionsPython interview questions
Python interview questionsPragati Singh
1.9K visualizações5 slides
Python interview questions for experience por
Python interview questions for experiencePython interview questions for experience
Python interview questions for experienceMYTHILIKRISHNAN4
43 visualizações1 slide
Python interview questions por
Python interview questionsPython interview questions
Python interview questionsPragati Singh
810 visualizações9 slides
Python Interview Questions And Answers 2019 | Edureka por
Python Interview Questions And Answers 2019 | EdurekaPython Interview Questions And Answers 2019 | Edureka
Python Interview Questions And Answers 2019 | EdurekaEdureka!
2.1K visualizações42 slides
Chapter 5 - THREADING & REGULAR exp - MAULIK BORSANIYA por
Chapter 5 - THREADING & REGULAR exp - MAULIK BORSANIYAChapter 5 - THREADING & REGULAR exp - MAULIK BORSANIYA
Chapter 5 - THREADING & REGULAR exp - MAULIK BORSANIYAMaulik Borsaniya
325 visualizações9 slides

Mais conteúdo relacionado

Mais procurados

Introduction to Python por
Introduction to Python Introduction to Python
Introduction to Python amiable_indian
36.8K visualizações62 slides
Python training por
Python trainingPython training
Python trainingKunalchauhan76
3.7K visualizações51 slides
Python Presentation por
Python PresentationPython Presentation
Python PresentationNarendra Sisodiya
89.3K visualizações47 slides
Python cheat-sheet por
Python cheat-sheetPython cheat-sheet
Python cheat-sheetsrinivasanr281952
328 visualizações26 slides
Let’s Learn Python An introduction to Python por
Let’s Learn Python An introduction to Python Let’s Learn Python An introduction to Python
Let’s Learn Python An introduction to Python Jaganadh Gopinadhan
3.6K visualizações62 slides
Introduction to Python Pandas for Data Analytics por
Introduction to Python Pandas for Data AnalyticsIntroduction to Python Pandas for Data Analytics
Introduction to Python Pandas for Data AnalyticsPhoenix
1.7K visualizações115 slides

Mais procurados(20)

Introduction to Python por amiable_indian
Introduction to Python Introduction to Python
Introduction to Python
amiable_indian36.8K visualizações
Python training por Kunalchauhan76
Python trainingPython training
Python training
Kunalchauhan763.7K visualizações
Python Presentation por Narendra Sisodiya
Python PresentationPython Presentation
Python Presentation
Narendra Sisodiya89.3K visualizações
Python cheat-sheet por srinivasanr281952
Python cheat-sheetPython cheat-sheet
Python cheat-sheet
srinivasanr281952328 visualizações
Let’s Learn Python An introduction to Python por Jaganadh Gopinadhan
Let’s Learn Python An introduction to Python Let’s Learn Python An introduction to Python
Let’s Learn Python An introduction to Python
Jaganadh Gopinadhan3.6K visualizações
Introduction to Python Pandas for Data Analytics por Phoenix
Introduction to Python Pandas for Data AnalyticsIntroduction to Python Pandas for Data Analytics
Introduction to Python Pandas for Data Analytics
Phoenix 1.7K visualizações
First Steps in Python Programming por Dozie Agbo
First Steps in Python ProgrammingFirst Steps in Python Programming
First Steps in Python Programming
Dozie Agbo202 visualizações
Zero to Hero - Introduction to Python3 por Chariza Pladin
Zero to Hero - Introduction to Python3Zero to Hero - Introduction to Python3
Zero to Hero - Introduction to Python3
Chariza Pladin7.6K visualizações
PYTHON -Chapter 2 - Functions, Exception, Modules and Files -MAULIK BOR... por Maulik Borsaniya
PYTHON -Chapter 2 - Functions,   Exception, Modules  and    Files -MAULIK BOR...PYTHON -Chapter 2 - Functions,   Exception, Modules  and    Files -MAULIK BOR...
PYTHON -Chapter 2 - Functions, Exception, Modules and Files -MAULIK BOR...
Maulik Borsaniya1.5K visualizações
Python Foundation – A programmer's introduction to Python concepts & style por Kevlin Henney
Python Foundation – A programmer's introduction to Python concepts & stylePython Foundation – A programmer's introduction to Python concepts & style
Python Foundation – A programmer's introduction to Python concepts & style
Kevlin Henney6.8K visualizações
Python 3 Programming Language por Tahani Al-Manie
Python 3 Programming LanguagePython 3 Programming Language
Python 3 Programming Language
Tahani Al-Manie11.5K visualizações
11 Unit 1 Chapter 02 Python Fundamentals por praveenjigajinni
11  Unit 1 Chapter 02 Python Fundamentals11  Unit 1 Chapter 02 Python Fundamentals
11 Unit 1 Chapter 02 Python Fundamentals
praveenjigajinni5.1K visualizações
Intro to Functions Python por primeteacher32
Intro to Functions PythonIntro to Functions Python
Intro to Functions Python
primeteacher321.5K visualizações
Learn Python The Hard Way Presentation por Amira ElSharkawy
Learn Python The Hard Way PresentationLearn Python The Hard Way Presentation
Learn Python The Hard Way Presentation
Amira ElSharkawy913 visualizações
Ground Gurus - Python Code Camp - Day 3 - Classes por Chariza Pladin
Ground Gurus - Python Code Camp - Day 3 - ClassesGround Gurus - Python Code Camp - Day 3 - Classes
Ground Gurus - Python Code Camp - Day 3 - Classes
Chariza Pladin228 visualizações
Introduction to Python programming Language por MansiSuthar3
Introduction to Python programming LanguageIntroduction to Python programming Language
Introduction to Python programming Language
MansiSuthar3145 visualizações
Fundamentals of Python Programming por Kamal Acharya
Fundamentals of Python ProgrammingFundamentals of Python Programming
Fundamentals of Python Programming
Kamal Acharya9.8K visualizações
Introduction to Python - Part Three por amiable_indian
Introduction to Python - Part ThreeIntroduction to Python - Part Three
Introduction to Python - Part Three
amiable_indian4.8K visualizações

Similar a Python Interview Questions And Answers

Programming in Python por
Programming in Python Programming in Python
Programming in Python Tiji Thomas
1.1K visualizações45 slides
Python interview questions and answers por
Python interview questions and answersPython interview questions and answers
Python interview questions and answerskavinilavuG
118 visualizações22 slides
set.pptx por
set.pptxset.pptx
set.pptxsatyabratPanda2
2 visualizações23 slides
Python Interview Questions For Experienced por
Python Interview Questions For ExperiencedPython Interview Questions For Experienced
Python Interview Questions For Experiencedzynofustechnology
63 visualizações10 slides
Python Interview Questions | Python Interview Questions And Answers | Python ... por
Python Interview Questions | Python Interview Questions And Answers | Python ...Python Interview Questions | Python Interview Questions And Answers | Python ...
Python Interview Questions | Python Interview Questions And Answers | Python ...Simplilearn
1.8K visualizações68 slides
Programming with Python - Week 3 por
Programming with Python - Week 3Programming with Python - Week 3
Programming with Python - Week 3Ahmet Bulut
648 visualizações47 slides

Similar a Python Interview Questions And Answers(20)

Programming in Python por Tiji Thomas
Programming in Python Programming in Python
Programming in Python
Tiji Thomas1.1K visualizações
Python interview questions and answers por kavinilavuG
Python interview questions and answersPython interview questions and answers
Python interview questions and answers
kavinilavuG118 visualizações
Python Interview Questions For Experienced por zynofustechnology
Python Interview Questions For ExperiencedPython Interview Questions For Experienced
Python Interview Questions For Experienced
zynofustechnology63 visualizações
Python Interview Questions | Python Interview Questions And Answers | Python ... por Simplilearn
Python Interview Questions | Python Interview Questions And Answers | Python ...Python Interview Questions | Python Interview Questions And Answers | Python ...
Python Interview Questions | Python Interview Questions And Answers | Python ...
Simplilearn1.8K visualizações
Programming with Python - Week 3 por Ahmet Bulut
Programming with Python - Week 3Programming with Python - Week 3
Programming with Python - Week 3
Ahmet Bulut648 visualizações
Python For Data Science.pptx por rohithprabhas1
Python For Data Science.pptxPython For Data Science.pptx
Python For Data Science.pptx
rohithprabhas123 visualizações
Improve Your Edge on Machine Learning - Day 1.pptx por CatherineVania1
Improve Your Edge on Machine Learning - Day 1.pptxImprove Your Edge on Machine Learning - Day 1.pptx
Improve Your Edge on Machine Learning - Day 1.pptx
CatherineVania120 visualizações
Python advance por Deepak Chandella
Python advancePython advance
Python advance
Deepak Chandella149 visualizações
Advance python por pulkit agrawal
Advance pythonAdvance python
Advance python
pulkit agrawal175 visualizações
Python Objects por MuhammadBakri13
Python ObjectsPython Objects
Python Objects
MuhammadBakri13923 visualizações
Automation Testing theory notes.pptx por NileshBorkar12
Automation Testing theory notes.pptxAutomation Testing theory notes.pptx
Automation Testing theory notes.pptx
NileshBorkar1218 visualizações
CS 360 LAB 3 STRINGS, FUNCTIONS, AND METHODSObjective The purpos.docx por faithxdunce63732
CS 360 LAB 3 STRINGS, FUNCTIONS, AND METHODSObjective The purpos.docxCS 360 LAB 3 STRINGS, FUNCTIONS, AND METHODSObjective The purpos.docx
CS 360 LAB 3 STRINGS, FUNCTIONS, AND METHODSObjective The purpos.docx
faithxdunce6373211 visualizações
pythonlibrariesandmodules-210530042906.docx por RameshMishra84
pythonlibrariesandmodules-210530042906.docxpythonlibrariesandmodules-210530042906.docx
pythonlibrariesandmodules-210530042906.docx
RameshMishra8415 visualizações
Programming in C sesion 2 por Prerna Sharma
Programming in C sesion 2Programming in C sesion 2
Programming in C sesion 2
Prerna Sharma974 visualizações
ISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docx por priestmanmable
ISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docxISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docx
ISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docx
priestmanmable6 visualizações
Python - Data Collection por JoseTanJr
Python - Data CollectionPython - Data Collection
Python - Data Collection
JoseTanJr37 visualizações
A Gentle Introduction to Coding ... with Python por Tariq Rashid
A Gentle Introduction to Coding ... with PythonA Gentle Introduction to Coding ... with Python
A Gentle Introduction to Coding ... with Python
Tariq Rashid1.2K visualizações
Data structures using C por Pdr Patnaik
Data structures using CData structures using C
Data structures using C
Pdr Patnaik3.7K visualizações

Mais de H2Kinfosys

JIRA Introduction | JIRA Tutorial | Atlassian JIRA Training | H2kinfosys por
JIRA Introduction | JIRA Tutorial | Atlassian JIRA Training | H2kinfosysJIRA Introduction | JIRA Tutorial | Atlassian JIRA Training | H2kinfosys
JIRA Introduction | JIRA Tutorial | Atlassian JIRA Training | H2kinfosysH2Kinfosys
4.6K visualizações16 slides
Mobile Apps Telecommunication Doc por
Mobile Apps Telecommunication DocMobile Apps Telecommunication Doc
Mobile Apps Telecommunication DocH2Kinfosys
2.5K visualizações17 slides
Mobile Apps Testing Tele communication Doc por
Mobile Apps Testing Tele communication DocMobile Apps Testing Tele communication Doc
Mobile Apps Testing Tele communication DocH2Kinfosys
1.9K visualizações17 slides
Health Care Project Overview from H2kInfosys LLC por
Health Care Project Overview from H2kInfosys LLCHealth Care Project Overview from H2kInfosys LLC
Health Care Project Overview from H2kInfosys LLCH2Kinfosys
7.6K visualizações26 slides
Testcase cyclos excel document por
Testcase cyclos excel documentTestcase cyclos excel document
Testcase cyclos excel documentH2Kinfosys
2.8K visualizações8 slides
Test plan cyclos por
Test plan cyclosTest plan cyclos
Test plan cyclosH2Kinfosys
7.4K visualizações14 slides

Mais de H2Kinfosys (18)

JIRA Introduction | JIRA Tutorial | Atlassian JIRA Training | H2kinfosys por H2Kinfosys
JIRA Introduction | JIRA Tutorial | Atlassian JIRA Training | H2kinfosysJIRA Introduction | JIRA Tutorial | Atlassian JIRA Training | H2kinfosys
JIRA Introduction | JIRA Tutorial | Atlassian JIRA Training | H2kinfosys
H2Kinfosys 4.6K visualizações
Mobile Apps Telecommunication Doc por H2Kinfosys
Mobile Apps Telecommunication DocMobile Apps Telecommunication Doc
Mobile Apps Telecommunication Doc
H2Kinfosys 2.5K visualizações
Mobile Apps Testing Tele communication Doc por H2Kinfosys
Mobile Apps Testing Tele communication DocMobile Apps Testing Tele communication Doc
Mobile Apps Testing Tele communication Doc
H2Kinfosys 1.9K visualizações
Health Care Project Overview from H2kInfosys LLC por H2Kinfosys
Health Care Project Overview from H2kInfosys LLCHealth Care Project Overview from H2kInfosys LLC
Health Care Project Overview from H2kInfosys LLC
H2Kinfosys 7.6K visualizações
Testcase cyclos excel document por H2Kinfosys
Testcase cyclos excel documentTestcase cyclos excel document
Testcase cyclos excel document
H2Kinfosys 2.8K visualizações
Test plan cyclos por H2Kinfosys
Test plan cyclosTest plan cyclos
Test plan cyclos
H2Kinfosys 7.4K visualizações
HealthCare Project Test Case writing guidelines por H2Kinfosys
HealthCare Project Test Case writing guidelinesHealthCare Project Test Case writing guidelines
HealthCare Project Test Case writing guidelines
H2Kinfosys 10.1K visualizações
Letters test cases por H2Kinfosys
Letters test casesLetters test cases
Letters test cases
H2Kinfosys 6K visualizações
Health Care Project Testing Process por H2Kinfosys
Health Care Project Testing ProcessHealth Care Project Testing Process
Health Care Project Testing Process
H2Kinfosys 14.8K visualizações
Test Plan Template por H2Kinfosys
Test Plan TemplateTest Plan Template
Test Plan Template
H2Kinfosys 2.3K visualizações
Test Plan Template por H2Kinfosys
Test Plan TemplateTest Plan Template
Test Plan Template
H2Kinfosys 9.2K visualizações
ETL Testing Interview Questions and Answers por H2Kinfosys
ETL Testing Interview Questions and AnswersETL Testing Interview Questions and Answers
ETL Testing Interview Questions and Answers
H2Kinfosys 44.2K visualizações
CRM Project - H2Kinfosys por H2Kinfosys
CRM Project - H2KinfosysCRM Project - H2Kinfosys
CRM Project - H2Kinfosys
H2Kinfosys 11.2K visualizações
Online Banking Business Requirement Document por H2Kinfosys
Online Banking Business Requirement DocumentOnline Banking Business Requirement Document
Online Banking Business Requirement Document
H2Kinfosys 71.7K visualizações
Online Shopping Cart Business Requirement Dcoument por H2Kinfosys
Online Shopping Cart Business Requirement DcoumentOnline Shopping Cart Business Requirement Dcoument
Online Shopping Cart Business Requirement Dcoument
H2Kinfosys 54.3K visualizações
QA Interview Questions With Answers por H2Kinfosys
QA Interview Questions With AnswersQA Interview Questions With Answers
QA Interview Questions With Answers
H2Kinfosys 43.2K visualizações
Basic Interview Questions por H2Kinfosys
Basic Interview QuestionsBasic Interview Questions
Basic Interview Questions
H2Kinfosys 10.7K visualizações
SDLC software testing por H2Kinfosys
SDLC software testingSDLC software testing
SDLC software testing
H2Kinfosys 3.5K visualizações

Último

DRaaS using Snapshot copy and destination selection (DRaaS) - Alexandre Matti... por
DRaaS using Snapshot copy and destination selection (DRaaS) - Alexandre Matti...DRaaS using Snapshot copy and destination selection (DRaaS) - Alexandre Matti...
DRaaS using Snapshot copy and destination selection (DRaaS) - Alexandre Matti...ShapeBlue
98 visualizações29 slides
Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P... por
Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P...Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P...
Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P...ShapeBlue
154 visualizações62 slides
Backroll, News and Demo - Pierre Charton, Matthias Dhellin, Ousmane Diarra - ... por
Backroll, News and Demo - Pierre Charton, Matthias Dhellin, Ousmane Diarra - ...Backroll, News and Demo - Pierre Charton, Matthias Dhellin, Ousmane Diarra - ...
Backroll, News and Demo - Pierre Charton, Matthias Dhellin, Ousmane Diarra - ...ShapeBlue
146 visualizações15 slides
Elevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlue por
Elevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlueElevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlue
Elevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlueShapeBlue
179 visualizações7 slides
Confidence in CloudStack - Aron Wagner, Nathan Gleason - Americ por
Confidence in CloudStack - Aron Wagner, Nathan Gleason - AmericConfidence in CloudStack - Aron Wagner, Nathan Gleason - Americ
Confidence in CloudStack - Aron Wagner, Nathan Gleason - AmericShapeBlue
88 visualizações9 slides
Setting Up Your First CloudStack Environment with Beginners Challenges - MD R... por
Setting Up Your First CloudStack Environment with Beginners Challenges - MD R...Setting Up Your First CloudStack Environment with Beginners Challenges - MD R...
Setting Up Your First CloudStack Environment with Beginners Challenges - MD R...ShapeBlue
132 visualizações15 slides

Último(20)

DRaaS using Snapshot copy and destination selection (DRaaS) - Alexandre Matti... por ShapeBlue
DRaaS using Snapshot copy and destination selection (DRaaS) - Alexandre Matti...DRaaS using Snapshot copy and destination selection (DRaaS) - Alexandre Matti...
DRaaS using Snapshot copy and destination selection (DRaaS) - Alexandre Matti...
ShapeBlue98 visualizações
Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P... por ShapeBlue
Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P...Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P...
Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P...
ShapeBlue154 visualizações
Backroll, News and Demo - Pierre Charton, Matthias Dhellin, Ousmane Diarra - ... por ShapeBlue
Backroll, News and Demo - Pierre Charton, Matthias Dhellin, Ousmane Diarra - ...Backroll, News and Demo - Pierre Charton, Matthias Dhellin, Ousmane Diarra - ...
Backroll, News and Demo - Pierre Charton, Matthias Dhellin, Ousmane Diarra - ...
ShapeBlue146 visualizações
Elevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlue por ShapeBlue
Elevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlueElevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlue
Elevating Privacy and Security in CloudStack - Boris Stoyanov - ShapeBlue
ShapeBlue179 visualizações
Confidence in CloudStack - Aron Wagner, Nathan Gleason - Americ por ShapeBlue
Confidence in CloudStack - Aron Wagner, Nathan Gleason - AmericConfidence in CloudStack - Aron Wagner, Nathan Gleason - Americ
Confidence in CloudStack - Aron Wagner, Nathan Gleason - Americ
ShapeBlue88 visualizações
Setting Up Your First CloudStack Environment with Beginners Challenges - MD R... por ShapeBlue
Setting Up Your First CloudStack Environment with Beginners Challenges - MD R...Setting Up Your First CloudStack Environment with Beginners Challenges - MD R...
Setting Up Your First CloudStack Environment with Beginners Challenges - MD R...
ShapeBlue132 visualizações
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlue por ShapeBlue
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlueCloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlue
CloudStack Object Storage - An Introduction - Vladimir Petrov - ShapeBlue
ShapeBlue93 visualizações
Zero to Cloud Hero: Crafting a Private Cloud from Scratch with XCP-ng, Xen Or... por ShapeBlue
Zero to Cloud Hero: Crafting a Private Cloud from Scratch with XCP-ng, Xen Or...Zero to Cloud Hero: Crafting a Private Cloud from Scratch with XCP-ng, Xen Or...
Zero to Cloud Hero: Crafting a Private Cloud from Scratch with XCP-ng, Xen Or...
ShapeBlue158 visualizações
Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit... por ShapeBlue
Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit...Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit...
Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit...
ShapeBlue117 visualizações
Extending KVM Host HA for Non-NFS Storage - Alex Ivanov - StorPool por ShapeBlue
Extending KVM Host HA for Non-NFS Storage -  Alex Ivanov - StorPoolExtending KVM Host HA for Non-NFS Storage -  Alex Ivanov - StorPool
Extending KVM Host HA for Non-NFS Storage - Alex Ivanov - StorPool
ShapeBlue84 visualizações
Live Demo Showcase: Unveiling Dell PowerFlex’s IaaS Capabilities with Apache ... por ShapeBlue
Live Demo Showcase: Unveiling Dell PowerFlex’s IaaS Capabilities with Apache ...Live Demo Showcase: Unveiling Dell PowerFlex’s IaaS Capabilities with Apache ...
Live Demo Showcase: Unveiling Dell PowerFlex’s IaaS Capabilities with Apache ...
ShapeBlue85 visualizações
Data Integrity for Banking and Financial Services por Precisely
Data Integrity for Banking and Financial ServicesData Integrity for Banking and Financial Services
Data Integrity for Banking and Financial Services
Precisely78 visualizações
CloudStack Managed User Data and Demo - Harikrishna Patnala - ShapeBlue por ShapeBlue
CloudStack Managed User Data and Demo - Harikrishna Patnala - ShapeBlueCloudStack Managed User Data and Demo - Harikrishna Patnala - ShapeBlue
CloudStack Managed User Data and Demo - Harikrishna Patnala - ShapeBlue
ShapeBlue94 visualizações
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue por ShapeBlue
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue
2FA and OAuth2 in CloudStack - Andrija Panić - ShapeBlue
ShapeBlue103 visualizações
Igniting Next Level Productivity with AI-Infused Data Integration Workflows por Safe Software
Igniting Next Level Productivity with AI-Infused Data Integration Workflows Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Safe Software385 visualizações
State of the Union - Rohit Yadav - Apache CloudStack por ShapeBlue
State of the Union - Rohit Yadav - Apache CloudStackState of the Union - Rohit Yadav - Apache CloudStack
State of the Union - Rohit Yadav - Apache CloudStack
ShapeBlue253 visualizações
The Power of Heat Decarbonisation Plans in the Built Environment por IES VE
The Power of Heat Decarbonisation Plans in the Built EnvironmentThe Power of Heat Decarbonisation Plans in the Built Environment
The Power of Heat Decarbonisation Plans in the Built Environment
IES VE69 visualizações
What’s New in CloudStack 4.19 - Abhishek Kumar - ShapeBlue por ShapeBlue
What’s New in CloudStack 4.19 - Abhishek Kumar - ShapeBlueWhat’s New in CloudStack 4.19 - Abhishek Kumar - ShapeBlue
What’s New in CloudStack 4.19 - Abhishek Kumar - ShapeBlue
ShapeBlue222 visualizações
Business Analyst Series 2023 - Week 4 Session 7 por DianaGray10
Business Analyst Series 2023 -  Week 4 Session 7Business Analyst Series 2023 -  Week 4 Session 7
Business Analyst Series 2023 - Week 4 Session 7
DianaGray10126 visualizações

Python Interview Questions And Answers

  • 1. Job Oriented || Instructor Led || Face2Face True Live I.T Training for Everyone Python Interview questions and Answers 1. How do you make a loop in Python 3? There are 3 main ways to make a loop (or a loop like) construct: While A while loop is the simplest type of loop, where the body of the loop is repeated until a condition becomes False 1. even =True 2. while even: 3. num=input('Provide an even integer > ') 4. even =(int(num)%2==0) For loop A for loop is probably the most common type of loop in Python. A for loop will select items from any iterable. In Python an iterable is any container (list, tuple, set, dictionary), as well as many other important objects such as generator function, generator expressions, the results of builtin functions such as filter, map, range and many other items. An example of a for loop :
  • 2. 1. the_list=[1,2,3,4,5,6,7,8,9] 2. for item inthe_list: 3. print(item, item**2) Comprehensions Comprehensions are a loop like construct for use in building lists, sets and dictionaries A list comprehension example : 1. # Build the list [0,2,4,6,8,10] 2. my_list=[x for x inrange(11)if x%2==0] 2. What is the difference between pop() and remove() in a list in Python? pop() takes an index as its argument and will remove the element at that index. If no argument is specified, pop() will remove the last element. pop()also returns the element it removed. remove() takes an element as its argument and removes it if it’s in the list, otherwise an exception will be thrown. 1. mylist=['zero','one','two','three'] 2. 3. print(mylist.pop())# removes last element 4. print(mylist.pop(1))# removes a specific element 5. mylist.remove('zero')# removes an element by name 6. print(mylist) 7. mylist.remove('foo')# ...and throws an exception if not in list 3. Python (programming language). How do you check if a given key already exists in a dictionary? use the ‘in’ operator for a simple membership test, but in some cases, a call to the get method might be better. Using get to retrieve a value if it exists, and a default value if it doesn’t for example: val=my_dict.get(key,None) Using ‘in’ to decide which operation is needed : If you are testing for an existing key, and wondering whether to insert or append - there is another thing you can do: if you have code like this : 1. if key inmy_dict: 2. my_dict[key].append(value) 3. else: 4. my_dict[key]=[]
  • 3. 4. What does * and ** means in Python? Is it to do with pointers and addresses? There are a number of uses of * and ** :  * is the multiplication operator (or in the case of strings a repetition operator). Classes in other libraries may use ‘*’ for other reasons, but nearly always it is multiplication in some form.  ** is an exponent operator such that in normal numbers x ** y is the mathematical method for computing xyxy 5. What's the purpose of __main__ in python? How it is used and when? For every module that is loaded/imported into a Python program, Python assigns a special attribute called __name__. The rules for how __name__ is set are not that complex :  If the module is the first module being executed, then __name__ is set to ‘__main__’  If the module is imported in some way, then __name__ is set to the name of the module. 6. Why are lambdas useful in Python? What is an example that shows such usefulness if any? An example of the use case for lambdas is doing sorts, or map, or filter or reduce. For example to remove odd numbers from a list: 1. evens_only=list(filter(lambda x:x %2==0, numbers)) So here the filter takes a function which needs to return true for every value to be contained in the new iterable. To sort a list of tuples, using only the 2nd item in the tuple as the sort item: 1. sorted=sorted(un_sorted_list_of_tuples, key=lambda x: x[1]) Without the key the sorted function will sort based on the entire tuple (which will compare both the 1st and 2nd items). The sort method on lists works similarly if you want to sort in place. Using reduce to multiply a list of values together 2. product =reduce(lambdax,y: x*y,list_of_numbers,1) Here reduce expects a function (such as a lambda) that takes two values and will return one).
  • 4. Another use case is for map to apply a transformation to every entry in a sequence - for instance: 1. fromitertoolsimport count 2. for square inmap(lambda x:x*x, count()): 3. print(square): 4. if square >100: 5. break This code uses map to generate a sequence of square numbers up to but not greater than 100. Itertools.count is a great function that produces a sequence of numbers starting from 1 and never ending ( similar to range but without an end). 7. How do you randomly select an item from a list in Python? You can achieve this easily using choice method from random module 1. import random 2. l =[1,2,3,4,5] 3. selected =random.choice(l) 4. print(selected) An alternative method would be selecting a random index using random.randint. But random.choice is more convenient for this purpose. 8. What are Python modules? A module is a collection is functions, classes and data which together provide related set of functionality. For instance you could have a module which implements the http protocol, and another module which create jpeg files. To make use of a module, and the functionality in it - a python program simply has to import it. You also find the Python has packages - A package is a set of modules - which are related - to each other; An example would be the Django package. You have a set of modules which define models, and another which supports web forms, another which supports views, another which supports data validation and so on. They all relate to each to to provide the Django package of functionality for writing web servers. 9. What are the differences between tuples and lists in Python? The main difference:  lists can be changed once created - you can append, and delete elements from the list, and change individual elements - they are mutable.  tuple, once created, cannot be changed - you cannot append or delete elements from a tuple, or change individual elements - they are immutable. 10. Why would you want a data structure that can’t be changed once created?
  • 5.  Tuples are smaller in terms of memory used than a list with the same number and type of elements.  Tuples are ideally suited for data where the order of elements is well understood by convention - for instance co-ordinates (x,y,z), colours (RGB or HSV). If you need a tuple type structure but with named elements, not index numbers, then you can use the NamedTuple type.  In general, a tuple can be stored in a set, or form the key for a dictionary - whereas as a list cannot be. In python terms it is hashable. (Although you can make tuples un-hashable by choosing the wrong data types). 11. What do 'write', 'read' and 'append' signify in Python's open() function? Write, read and append are what are termed the access mode. They indicate what the intended operation on the file will be. They have two important effects: 1. They relate directly to the permissions on a file - All O/S implement in some form the idea of read write permission on a file. Attempting to open a file for writing or appending that the program doesn’t have permission to write to, or opening a file for reading that the program doesn’t have permission to read is by definition an error, and in Python will raise an exception - specifically PermissionError. 2. They directly relate to how the file is opened, and where the file pointer is set to (the O/S will maintain a file pointer which is where in the file the next read or write will occur - it is normally a count from zero of the number of bytes in the file.):  read : The file is opened with the file pointer set to zero - i.e. read from the start of the file.  write : The file is opened, the file length is set to zero, and the file pointer is set to zero - i.e. write from the start of the file ignoring all previous contents  append : The file is opened, the file pointer is set to the end of the file - i.e. write from the end of the file, retaining all previous contents. 12. How do I write a program about summing the digits of a number in Python? The answers so far do this numerically, which is perfectly fine, but I think it’s more Pythonic to consider the number as a string of digits, and iterate through it: 1. >>>num=123456789 2. >>>sum_of_digits=0 3. >>>for digit in str(num): 4. ...sum_of_digits+=int(digit) 5. ... 6. >>>sum_of_digits 7. 45 A more advanced solution would eschew the loop and use a generator expression. There’s still a loop in there, but sum_of_digits is computed all in one go, so we don’t have to set it to 0 first: 1. >>>num=123456789
  • 6. 2. >>>sum_of_digits= sum(int(digit)for digit in str(num)) 3. >>>sum_of_digits 4. 45 13. What is “_init_” in Python? __init__ (double underscore “init” followed by double underscore), when it’s used as the name of a method for a class in Python, is an instance “initialization” function. In Python most (almost all) of the “special” class methods and other attributes are wrapped in “double underscore” characters. Theare, sometimes referred to as “dunder” methods (or attributes). 14. Why do python classes always require a self parameter? I will explain this with an example. I have created here a class Human which I’m defining with Self. Here I have created the object, Will. 1. classHuman(): 2. 3. def __init__(self,name,gender): 4. 5. self.name = name 6. self.gender= gender 7. 8. defspeak_name(self):// the self-going to speak the name 9. print MY NameisWill%self.name 10. 11. will =Human("William","Male") 12. 13. print will.name 14. printwill.gender 15. 16. will.speak_name() So, self-represents the object itself. The Object is will. Then I have defined a method speak_name. ( A method is different from Function because it is part of the class) It can be called from the object. Self is an object when you call self, it refers to will. This is how self-works. Whenever you use self. something, actually you’re assigning new value or variable to the object which can be accessed by the python program everywhere. 15. In Python, what is NumPy? How is it used? Python NumPy is cross platform & BSD licensed. You often used it with packages like Matplotlib & SciPy. This can be an alternative to MATLAB. Numpy is a portmanteau of the words NUMerical and Python.
  • 7. Features of Numpy-  NumPy stands on CPython, a non optimizing bytecode interpreter.  Multidimensional arrays.  Functions & operators for these arrays  Python alternatives to MATLAB.  ndarray- n-dimensional arrays.  Fourier transforms & shapes manipulation.  Linear algebra & random number generation. Register & post msgs in Forums:http://h2kinfosys.com/forums/ Like us on FACE BOOK http://www.facebook.com/H2KInfosysLLC Videos : http://www.youtube.com/user/h2kinfosys