Certified Associate in Python Programming (PCAP-31-03) — Question 25
What is the expected behavior of the following code?
the_list = "alpha;beta;gamma".split(";")
the_string = ''.join(the_list)
print(the_string.isalpha())
Answer options
- A. it outputs True
- B. it outputs False
- C. it outputs nothing
- D. it raises an exception
Correct answer: A
Explanation
The code joins the elements of 'the_list' into a single string, resulting in 'alphabeta gamma'. The method isalpha() checks if the string contains only alphabetic characters, which it does, hence it outputs True. The other options are incorrect as the output is indeed a boolean value, not an exception or empty output.