Monday 18 April 2022

Top 22 Python Interview Questions and Answers on String ? String manipulation with Python

 



Python Interview Question & Answers Set - 01

Automation Testing/SDET Framework Design Link

Java Related Interview Question Set LINK

GIT Interview Question Set LINK 

12. How to define a multiline string in python?

Ans :
str = """This is 
a multiline
string"""


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


13.  Let str = "string", then what is the output for print(mystr[-2:-1]) # 'n'

Ans: answer is "n"

14. How to concatenate string in Python?
    
Ans: we can do it in below three ways:

x = "Test "
y = "Automation"
z = x + y
print(x + y)
print("Test " + "Automation")
print(z)

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

Ans:
 Click Here For Answer

16. What is the output for below :

print("2.2" + "4.4") 



Ans: 2.24.4


17. What is the use of format() in python?


We can use the format() method after strings which are used to insert specified values inside strings.

We use “{}” to insert specified values.

There are three ways to insert values.

1. {valuename}

2. {valueindex}

3. {}


Example

print("Name:{name} and age:{age}".format(name=“Sid”, age=31))

print("Name:{0} and age:{1}".format(“Sid”, 31))

print("Name:{1} and age:{0}".format(“Sid”, 31))

print("Name:{} and age:{}".format(“Sid”, 31))


Output

Name:Sid and age:31

Name:Sid and age:31

Name:31 and age:Sid

Name:Sid and age:31

18.  What re the rules of variable naming in python?

Ans: Click Here For All The Rules

19. Correct 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")


21. What are the different environment variables in Python?

Ans: 

  • PYTHONPATH [locate the module files imported into a program]
  • PYTHONSTARTUP [contains the path of an initialization file containing Python source code]
  • PYTHONCASEOK [used in windows to instruct Python to find the first case-insensitive match in an import statement]
  • PYTHONHOME [it is an alternative module search path]

22. How to check number is prime or not in python?

Ans: num= 7
count=0
if num>1:
for i in range(1,num+1):
if(num%i)==0:
count=count+1
if count==2:
print("Number is prime")
else:
print("Number is not prime"

Important Escape Characters


Escape CharacterName
\’Single Quote
\\Backslash
\nNew Line
\tTab
\bBackspace
\”Double Quote

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

Introduction to Web Testing with Playwright

  Introduction to Web Testing with Playwright 📌  Telegram Group:  https://t.me/+FTf_NPb--GQ2ODhl 📌  YouTube channel:  https://lnkd.in/gGUG...