Computer Science, asked by nishavincent2304, 5 months ago

What is the output of the following code snippet?
f="Doctorate of Philosophy"
f.find('t',8,10)
A. 0 7
B. O 3
c. O -1
5
D. O
Error
< Previous
Next​

Answers

Answered by sukhamnu114
0

o error ≤ previous next a

Answered by mad210203
0

Output:

-1 (Option C is correct)

Explanation:

  • The find() function is used to the find the first occurrence of the word or specified value.
  • Syntax: stringname.find(word or value, starting position, ending position)
  • If the value is present, it returns the position of the word or specified value.
  • If the value is not present, it returns -1.

Program:

f='Doctorate of Philosophy'

f.find('t',8,10)

Let us understand the program.

f='Doctorate of Philosophy' #This statement is used to declare a string f and initialize it.

#This statement is used to find whether the value 't' is present in the positions from 8 to 10 or not.

f.find('t',8,10)

But in the positions from 8 to 10, 't' is not present.

So, the find function will return -1.

To check output, use the following code.

f='Doctorate of Philosophy'

output=f.find('t',8,10)

print(output)

Refer the attached image for the output.

Attachments:
Similar questions