Python Testing Interview Questions and Answers
by Bharathkumar, on Sep 11, 2022 3:39:27 PM
Q1).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
Q2).What Python frameworks do you know?
Ans: Framework called Web2py, PAMIE (Python automation Module for I. E.), The py.test framework
Q3).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.
Q4).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’)
Q5).The following is displayed by a print function call:
hello-how-are-you
Please write an example of a print function.
Ans: print(‘hello’ + ‘-‘ + ‘how’ + ‘-‘ + ‘are’ + ‘-‘ + ‘you’)
Q6).Question: What does the expression len(”) evaluate to?
Ans: 0
Q7).Considering the following code:
s = ‘catandapple’
Write an expression that evaluate to ‘apple’.
Ans: s[-5:]
Q8).Write an expression that evaluate to True
Ans: len(‘aaddgg’) == 6
Q9).Write the code that calculate the sum of even numbers from x1 till x2
Ans:
# Python Program to Calculate Sum of Even Numbers from 1 to N
maximum = int(input(" Please Enter the Maximum Value : "))
total = 0
for number in range(2, maximum + 1, 2):
print("{0}".format(number))
total = total + number
print("The Sum of Even Numbers from 1 to {0} = {1}".format(number, total))
Q10).What are “tuples”
Ans: Tuples are immutable sequences: they cannot be modified. Tuples use parentheses instead of square brackets: tup = (‘test’, 5, -0.2)
Q11).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 _.
Q12).What is the dictionary tipe in Python? How to Access Information From Dictionaries and Modify it?
Ans:
While indexing is used with other data types to access values, a dictionary uses keys . Keys can be used either inside square brackets [] or with the get() method. If we use the square brackets [] , KeyError is raised in case a key is not found in the dictionary.
Q13).To display a value in the console, what Python keyword do you use?
Ans:
print() key word is used to dispaly output on the console. Explanation: print function is to display output on the console.
Q14).Python file names traditionally end in what characters after a period?
Ans: (.py)
Strings in python are surrounded by either single quotation marks, or double quotation marks. 'hello' is the same as "hello".
Q15).An if statement can have how many elif parts?
Ans:
An If statement sets an condition with one or more if statement that will be used when a condition is met. There can be zero or more elif parts, and the else part is optional. The keyword 'elif' is short for 'else if', and is useful to avoid excessive indentation.
(Unlimited, i.e., 0 or more)
Q16).How many control objects are allowed in a frame?
Ans:
Unlimited, i.e., 0 or more
Q17).When you enter text into an input field and press enter, the text is passed to the input field’s event handler.
Ans:
The onchange event handler is not necessarily called for each alteration to an element's value. Please Note: You also should not use function keyword as your function name.
Q18).What is the data type of the text?
Ans: (string)
Q19).What does the draw handler parameter represent?
Ans: (The canvas)
Q20).What happens if you draw text outside the canvas coordinates?
Ans:
Some or none of the text is shown. Conceptually, the text is drawn at whatever coordinates are given, but only whatever text fits within the canvas coordinates is shown.
Q21).You want a timer to create exactly 1000 events. Suggest any solutions.
Ans:
Have a global counter for the number of timer calls. In the timer handler, increment the counter. In the timer handler, check the count and possibly stop the timer.
Q22).How many timers can you have running at once? (Unlimited)
Ans:
Q23).Give example of list
Ans: [1, 2, 3]
Q24).Give example of Tuple
Ans: (1, 2, 3)
Q25).Which types of data are immutable in Python?
Ans:
Numbers, Tuples, Strings, Booleans
Q26).Which types of data are mutable in Python?
Ans:
List
Q27).Question: What is the Lambda Functions in Python?
Ans: Lambda Functions in Python can be used to pass a function as an argument or can be used inside another statement. A lambda function has the syntax: lambda variable(s) : expression
Q28).What are Decorators in Python?
Ans: A decorator in Python is a function that wraps another function (it takes a function as an argument and returns a replacement function) Or another way to explain: The main function is called and its return value passed to the decorator and the decorator then returns a function that replaces the wrapped function.