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
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 Rules19. 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]
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 Character | Name |
---|---|
\’ | Single Quote |
\\ | Backslash |
\n | New Line |
\t | Tab |
\b | Backspace |
\” | Double Quote |
No comments:
Post a Comment