šŸ“¢ Too many exams? Don’t know which one suits you best? Book Your Free Expert šŸ‘‰ call Now!


    Question

    What is the output of the following part of python

    program? x = ("apple", "banana", "cherry") print(x)Ā 
    A ('apple', 'banana', 'cherry') Correct Answer Incorrect Answer
    B Cherry Correct Answer Incorrect Answer
    C Apple Correct Answer Incorrect Answer
    D Error Correct Answer Incorrect Answer

    Solution

    Correct answer: Ā  1. ('apple', 'banana', 'cherry') Why this is correct: x Ā is a tuple of three strings.Ā  print(x) Ā prints the Python representation of the tuple:Ā  ('apple', 'banana', 'cherry') . Why the others are wrong: 2 & 3.Ā  print(x) Ā prints the whole tuple, not a single element — to printĀ  "cherry" Ā you'd needĀ  print(x[2]) . 4. The code is valid Python and does not produce an error.

    Practice Next

    Relevant for Exams:

    ask-question