GPYC Exam QuestionsBrowse all questions from this exam

GPYC — Question 27


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

Show Answer
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

2 comments
Sign in to comment
mrmrmeOption: D
Mar 1, 2022

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

cmk428Option: D
May 15, 2024

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