Computer Science, asked by shahlatief886, 14 hours ago

(d) txt = "There are seven colours in rainbow" print("colors" in txt)​

Answers

Answered by Equestriadash
6

Given co‎de:

\tt txt\ =\ "There\ are\ seven\ colours\ in\ a\ rainbow"\\print("colors"\ in\ txt)

Output:

\tt False

The use of the \tt in operator in Python, is to check if the item on the left-hand side is present somewhere in the item on the right-hand side, or rather, to check if something is present in another item.

As per the question, the co‎de was trying to find if "colors" was present in the string "There are seven colours in a rainbow" assigned to the variable 'txt', which is not true, since 'colours' and 'colors' are both differently spelled, and hence it resulted in the output "False". In order for it to return 'True', they should be the exact same.

Such operators are known as membership operators. As the name suggests, it tries to see if an item is a member of another item.

Another such membership operator is \tt not\ in, which performs the exact opposite of what \tt in does. It checks if an item is NOT part of another item or not.

Hence, if in the question, the co‎de was \tt print("colors"\ not\ in\ txt), the output would be "True".

Answered by btsv66556
0

Answer:

V-VIOLET

I-INDIGO

B-BLUE

G-GREEN

Y-YELLOW

O-ORANGE

R-RED

Similar questions