What will be the output of print("Hello"[1])?

Master Python with the PCAP Certification! Explore interactive quizzes and detailed explanations to ensure your exam success. Gain confidence and get certified!

In Python, strings are indexed starting from 0. This means that each character in the string can be accessed by its position, where the first character has an index of 0, the second character has an index of 1, and so on.

In the case of the string "Hello", the indexing would work as follows:

  • 'H' is at index 0

  • 'e' is at index 1

  • 'l' is at index 2

  • 'l' is at index 3

  • 'o' is at index 4

When the code print("Hello"[1]) is executed, it retrieves the character that corresponds to index 1 in the string "Hello", which is 'e'. Therefore, the output when this code is run will be 'e', confirming that the choice indicating this output is indeed the correct one.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy