Thursday 19 May 2022

Top 33 Python Interview questions and Answers for SDET - QAE - SDE? Python Interview Questions on List

 



Python Interview Question & Answers Set - 01

Python Interview Q&A Set- 02

Automation Testing/SDET Framework Design Link

Java Related Interview Question Set LINK

GIT Interview Question Set LINK


If you are new to PYTHON then first check the post on How to Install Python on windows and mac?, once installation is complete then only checkout the below Q&A


How to take screenshot of the current window using Selenium-Python ?

Use the save_screenshot method provided by the webdriver:

from selenium import webdriver

driver = webdriver.Firefox()
driver.get('https://automationreinvented.blogspot.com/')
driver.save_screenshot('screenshot.png')
driver.quit()

If you are preparing for Selenium-Python Interview then also check below Q&A:


Python Interview Question & Answers Set - 01

Python Interview Q&A Set - 02

Python Interview Q&A Set - 03


23. What is Python Lists and give an example?

Python Lists are sequential data types, enclosed with square brackets([]) and elements are separated by comma(,).

Python Lists are mutable i.e. we can change any element(s) of lists if we want to change.

  # defining a list

testList = [1, 2, 3, 4, "Test", "Automation"]


24. How python list slicing works, try to solve below?


print only "test" "automation" from list = [1, 2, 3, 4, "Test", "Automation"]



List slicing: type the range of indexes to get the elements inside that range.


to print only test and automation we need to use :


print(list[4:5])


25. How to check if list contains an element?


Ans: we can use "in", for example:


list1 = [1,2,3,'test','automation']

'test' in list1


o/p True


26.What are the python frameworks you have used for Test Automation?


Ans:
 Click Here For Answer


27. What is the difference between append and extend?


.append() adds an object to the end of a list.

This also means appending a list adds that whole list as a single element, rather than appending each of its values.

a.append([7,8])

a #=> [3, 4, 5, 6, [7, 8]]

.extend() adds each value from a 2nd list as its own element. So extending a list with another list combines their values.

b = [1,2,3]

b.extend([4,5])

b #=> [1, 2, 3, 4, 5]


28. How to convert TuplesStringsSets to List?


Ans: we can use the list() method, it can convert any sequence datatype into lists.


Tuple = (1, 2, 3, 4)

List1 = list(myTuple)

String = “Automation”

List2 = list(myString)

Set = {1, 2, 3, 4}

List3 = list(Set)


29. What is the difference between “remove” and “pop”?


Ans: 

.remove() removes the first instance of a matching object. 

a = [ 'b', 'b', 'c', 'c']

a.remove('b')

O/p:  ['b', 'c', 'c']  //it has removed the first instance of b


.pop() removes an object by its index.

The difference between pop and del is that pop returns the popped element. This allows using a list like a stack.

a = [’t’, ’t’, ‘r’, ‘r’, 'c', 'c']

a.pop(4)

O/p: [’t’, ’t’, ‘r’, ‘r’, 'c'] //removed the 4th element that is c as index starts from 0

By default, pop removes the last element from a list if an index isn’t specified.


30. How to remove duplicate elements of list?


Ans: The east approach is converting to a set and back to a list, but it wont maintain the order.


list = [5, 6, 6, 1, 1]

list(set(list)) 

O/P=> [1, 5, 6]


BonusWhat are the different environment variables in Python?


31. How to count the occurrence of a specific object in a list?

Ans: 

The count() method returns the number of occurrences of a specific object. Below we return the number of times the string, “test” exists in a list .

list = [‘test’,’test’,’automation’,’reinvented’,’selenium’]

list.count(‘test’)

O/P:  2


32What are the rules of variable naming in python?

Ans: Click Here For All The Rules


33 What are the built-in List methods/functions provided by Python?


Method

Use

len()

returns list length

sort()

sorts the list

min()

returns the minimum value from list

max()

returns the maximum value from list

list()

converts a sequential data type to list

append()

adds an element at the end of the list

clear()

removes all elements from the list

copy()

returns the copied list

reverse()

reverses the order of the elements of the list

sum()

returns the sum of the elements of the list

range()

returns a sequence of numbers, starting from 0 by default, and increments by 1 (by default), and stops before a specified number

pop()

removes the element at the specified position

remove()

removes the item with the specified value

index()

returns the index of the first element with the specified value

insert()

Adds an element at the specified position



Details of all Python Methods: Click Here For Details



REVISION:

19Correct the below string:

print(“He is "A" genius”)


Ans: This will give syntax error, If we use backslash “\” followed by the character like ” then the problem will get resolved.


print(“He is \"A\" genius”)


20. How to replace Genius with fool in below string?
 Str = "He is a genius"


Ans: print(Str.replace("genius","fool")

8. How to convert an integer to string in python ? How to perform typecasting?


Ans:
var = 23

varString = str(var). //convert the int datatype to string


9. What is complex datatype in Python?


Ans: Click Here For Answer


10. Let we have below string, we want to print only Automation


x = "TestAutomation"


Ans: print(mystr[4:len(mystr)])


Python Interview Question & Answers Set - 01

Python Interview Q&A Set- 02


*******************************************************************
For any doubts or career guidance, arrange a 1:1 call with me 


********************************************************************

Check below link for question and answers with code:

Top API Interview Question 1-10

*************************************************

SeleniumWebdriver Automation Testing Interview Questions:

API Testing Interview Question Set:
https://automationreinvented.blogspot.com/search/label/Rest-API

 
Kubernetes Interview Question Set
https://automationreinvented.blogspot.com/search/label/Kubernetes

 
Docker Interview Question Set
https://automationreinvented.blogspot.com/2020/02/top-18-docker-commands-for-aytomation.html

 
Linux Interview question Set
https://automationreinvented.blogspot.com/search/label/Linux

 
Automation Testing/SDET Framework Design
https://automationreinvented.blogspot.com/search/label/FrameworkDesign


Java Related Interview Question Set

https://automationreinvented.blogspot.com/search/label/Java


GIT Interview Question Set:
https://automationreinvented.blogspot.com/search/label/GIT


Coding Interview Question Set:
https://automationreinvented.blogspot.com/search/label/Coding%20Questions
Mobile Testing Interview Question Set:
https://automationreinvented.blogspot.com/search/label/Mobile%20Testing
Python Interview Question Set for QAE - SDET - SDE:
https://automationreinvented.blogspot.com/search/label/Python


No comments:

Post a Comment

All Time Popular Posts

Most Featured Post

API Status Codes with examples for QA-Testers

  🔺 LinkedIn: https://www.linkedin.com/in/sidharth-shukla-77b53145/ 🔺 Telegram Group:  https://t.me/+FTf_NPb--GQ2ODhl 🏮In API testing, it...