Robotics & Artificial Intelligence
What should be the output of following program?
information = "My favorite subject is Python, I want to develop an AI application in Python"
val = information.find('T')
print(val)
if val > 1:
print("Python is a good programming language for AI applications ")
else:
print("My favorite subject is Python")
Python String Manipulation
2 Likes
Answer
Output
-1
My favorite subject is Python
Explanation
The find() function returns the index of the first occurrence of the specified value and returns −1 if the value is not found. Since the character 'T' (capital T) is not present in the given string, val becomes -1. As -1 is not greater than 1, the condition in the if statement is false, so the else part is executed.
Answered By
3 Likes
Related Questions
What would be the output of following program?
print("Hello\nWorld!") print("Python\tProgramming")What would be the output of following program?
str2 = "My classmate is Aayan" if str2.endswith("Aayan"): print("Aayan is studying in class X") else: print("Aayan is not the student of class X")Only single quotes can be used to declare a string in Python.
Blank spaces are counted as character in string.