hamburger menu
All Coursesall course arrow
adda247
reward-icon
adda247
    arrow
    arrow
    arrow
    For the following Python statement Msg = ('Good Day') What shall be the data type of Msg?
    Question

    For the following Python statement
    Msg = ('Good Day')
    What shall be the data type of Msg?

    A.

    tuple

    B.

    list

    C.

    Error in statement

    D.

    string

    Correct option is D


    The given statement:
    Msg = ('Good Day')
    will assign the string 'Good Day' to the variable Msg. Although the value is enclosed in parentheses, 'Good Day' is a string and not a tuple because there is only one value (the string itself). In Python, parentheses are used for grouping, but if there is only one element and no comma, it does not create a tuple; it simply creates the value it contains, which in this case is a string.
    Important Key Points:
    1. Tuples vs. Strings: In Python, a tuple is created using parentheses and a comma between elements (e.g., (1, 2)), whereas a string is a sequence of characters enclosed in quotes (e.g., 'Good Day').
    2. Single Element Tuple: To create a tuple with a single element, a comma must be included, such as ('Good Day',) (note the comma).
    3. Resulting Data Type: Since there is no comma, Msg is assigned a string, not a tuple.
    Knowledge Booster:
    · Option (a): tuple is incorrect because a tuple with a single element requires a comma (e.g., ('Good Day',)), and without a comma, this is a string.
    · Option (b): list is incorrect because lists in Python are defined using square brackets (e.g., ['Good Day']), not parentheses.
    · Option (c): There is no error in the statement. The syntax is valid, and it correctly assigns a string to the variable Msg.

    Free Tests

    Free
    Must Attempt

    DSSSB PRT Full Mock - 01

    languageIcon English
    • pdpQsnIcon200 Questions
    • pdpsheetsIcon200 Marks
    • timerIcon120 Mins
    languageIcon English
    Free
    Must Attempt

    Educational Psychology & Pedagogy - 01

    languageIcon English
    • pdpQsnIcon20 Questions
    • pdpsheetsIcon20 Marks
    • timerIcon15 Mins
    languageIcon English
    Free
    Must Attempt

    DSSSB PRT PYP Held on 7th March 2022 Shift 1

    languageIcon English
    • pdpQsnIcon200 Questions
    • pdpsheetsIcon200 Marks
    • timerIcon120 Mins
    languageIcon English
    test-prime-package

    Access ‘EMRS PGT’ Mock Tests with

    • 60000+ Mocks and Previous Year Papers
    • Unlimited Re-Attempts
    • Personalised Report Card
    • 500% Refund on Final Selection
    • Largest Community
    students-icon
    368k+ students have already unlocked exclusive benefits with Test Prime!
    Our Plans
    Monthsup-arrow