Exam GPYC All QuestionsBrowse all questions from this exam
Question 27

Examine the code snippet below. What will be the contents of the variable `˜i' during the loops first iteration?

    Correct Answer: D

    The code snippet uses the split() method on the string 'Python is a powerful language', which splits the string into a list of words based on whitespace. The resulting list is ['Python', 'is', 'a', 'powerful', 'language']. During the first iteration of the loop, the variable 'i' will be assigned the first element of this list, which is 'Python'.

Discussion
mrmrmeOption: D

the split turns it into a list, defaults to space as separator. Thus python is first word

cmk428Option: D

split() returns a list and splits on whitespace unless otherwise denoted. Python is in position [0], but the output will be Python.