Automation Testing Python Interview Questions
by Venkatesan M, on May 20, 2017 9:21:57 AM
Are you trying for a Python job? Here are the top frequently asked interview questions and answers to step-on the python interview. Dive into these Python interview questions and answers and see just how well-versed you are in this Python language.
Q1.What is Python? What are the benefits of using Python?
Ans: Python is a programming language with objects, modules, threads, exceptions and automatic memory management. The benefits of pythons are that it is simple and easy, portable, extensible, build-in data structure and it is an open source.
Q2. How Python can be used in software testing?
Ans:
1. To generate test data; parse test results; generate reports; testing API calls etc.
2. Python to extract requirements from a Word document.
3. For testing tasks automation, setting up environments for tests, extracting performance data, etc...
4. Testers use Python extensively in many companies with Selenium for test automation.
5. For writing desktop applications used by testers.
6. Test data manipulation.
7. To build test environment
8. Testing with IronPython on .NET
Q3. What Python frameworks do you know?
Ans: Framework called Web2py, PAMIE (Python automation Module for I. E.), The py.test framework
Q4.Question:What tools that helps Python development do you know?
Ans: There are good tools for helping Python development such as Notepad++ with the PyNPP plugin and Eclipse with PyDev and PyUnit.
Q5. The following is displayed by a print function call:
yesterday today tomorrow Please write an example of a print function.
Ans: print('yesterday\ntoday\ntomorrow')
Q6.The following is displayed by a print function call:
Ans: hello-how-are-you
Q7. Please write an example of a print function.
Ans: print('hello' + '-' + 'how' + '-' + 'are' + '-' + 'you')
Q8. What does the expression len('') evaluate to?
Ans: 0
Q9. Considering the following code:
s = 'catandapple'
Write an expression that evaluate to 'apple'.
Ans: s[-5:]
Q10. Write an expression that evaluate to True
Ans: len('aaddgg') == 6
Q11. What are "tuples"
Ans: Tuples are immutable sequences: they cannot be modified. Tuples use parentheses instead of square brackets: tup = ('test', 5, -0.2)
Q12. What are the rules for legal Python names?
Ans:
1. Names must start with a letter or _.
2. Names must contain only letters, digits, and _.
Q13. Which command do you use to exit help window or help command prompt?
Ans: quitWhen you type quit at the help’s command prompt, python shell prompt will appear by closing the help window automatically
Q14. Does the functions help() and dir() list the names of all the built_in functions and variables? If no, how would you list them?
Ans: No. Built-in functions such as max(), min(), filter(), map(), etc is not apparent immediately as they are
available as part of standard module.To view them, we can pass the module ” builtins ” as an argument to “dir()”. It will display the
built-in functions, exceptions, and other objects as a list.>>>dir(__builtins )
[‘ArithmeticError’, ‘AssertionError’, ‘AttributeError’, ……… ]
Q15. Explain how Python does Compile-time and Run-time code checking?
Ans: Python performs some amount of compile-time checking, but most of the checks such as type, name, etc are postponed until code execution. Consequently, if the Python code references a user -defined function that does not exist, the code will compile successfully. In fact, the code will fail with an exception only when the code execution path references the function which does not exists.
Q16. What is a “unittest” in Python?
Ans: The unit testing framework of Python is known as “unittest”. It supports the sharing of setups, automation testing, shutdown code for tests, aggregation of tests into collections, among others.
Q17. Define “slicing”.
Ans: “Slicing” is a mechanism to select a range of items from sequence types like list, tuple, strings etc.
Q18. What are generators in Python?
Ans: Generators are the means to implement iterators. It is a normal function except that it yields “expression” in the “function”.
Q19. Define “docstring”.
Ans: “Docstring” is a Python documentation string. It is the means to document Python “functions”, “modules” and “classes”.
Q20. How do you copy an object in Python?
Ans: copy.copy () or copy.deepcopy()
Q21. What is a “negative index”?
Ans: Python sequences can be indexed as positive and negative numbers. For ac positive index, 0 is the first number, 1 is the second etc. For a negative index, (-1) is the last index and (-2) is the second etc.
Q22. How do you convert a number into a string?
Ans: By using the inbuilt function str().
Q23. What is the difference between “Xrange” and “range”?
Ans: “Xrange” returns the “Xrange” object while range returns the “list” irrespective of the size of the “range”.
Q24. Define “module” and “package”.
Ans: Each Python program file is a “module”, which imports other modules like “objects” and “attributes”.
A Python program folder is a “package” of “modules”. A package can have “modules” or “subfolders”.
Q25. What is Python? What are the benefits of using Python?
Ans: Python is a programming language with objects, modules, threads, exceptions and automatic memory management. The benefits of pythons are that it is simple and easy, portable, extensible, build-in data structure and it is an open source.
Q26. What is PEP 8?
Ans: PEP 8 is a coding convention, a set of recommendation, about how to write your Python code more readable.
Q29. What is pickling and unpickling?
Ans: Pickle module accepts any Python object and converts it into a string representation and dumps it into a file by using dump function, this process is called pickling. While the process of retrieving original Python objects from the stored string representation is called unpickling.
Q30. How Python is interpreted?
Ans: Python language is an interpreted language. Python program runs directly from the source code. It converts the source code that is written by the programmer into an intermediate language, which is again translated into machine language that has to be executed.
Q31. How memory is managed in Python?
Ans:
- Python memory is managed by Python private heap space. All Python objects and data structures are located in a private heap. The programmer does not have an access to this private heap and interpreter takes care of this Python private heap.
- The allocation of Python heap space for Python objects is done by Python memory manager. The core API gives access to some tools for the programmer to code.
- Python also have an inbuilt garbage collector, which recycle all the unused memory and frees the memory and makes it available to the heap space.
You may also interested in...
- Python Flask Interview Questions and Answers
- Python Pandas Interview Questions and Answers
- Python Real Time Interview Questions and Answers
- Python Testing Interview Questions and Answers
- Top Python Interview Questions
- Data Science in Python Interview Questions and Answers
- Top 25 Python Interview Questions and Answers Prepared by Experts