PCAP Exam QuestionsBrowse all questions from this exam

PCAP Exam - Question 90


What is the expected behavior of the following code?

Show Answer
Correct Answer: C

The code provided is intended to show the use of Python's string manipulation methods. First, it uses the 'split' method on the string 'alpha;beta;gamma' with ':' as the delimiter, which results in a list containing one element: ['alpha;beta;gamma']. Then, it joins this list back into a single string 'alpha;beta;gamma' using the empty string '' as the join character. Finally, it checks if this string ('alpha;beta;gamma') is composed solely of alphabetic characters using the 'isalpha' method. Since the string contains the ';' character, which is not alphabetic, the 'isalpha' method will return False. Therefore, the expected behavior of the code is to print 'False'.

Discussion

11 comments
Sign in to comment
aferiverOption: C
Apr 13, 2023

C. False typo in alpha() The first line of code creates a list with one element, which is ‘alpha;beta;gamma’. However, the delimiter used in the split method is ‘:’ instead of ‘;’, so the list will only contain one element. The second line of code joins all elements in the list into a single string, which will be ‘alpha;beta;gamma’. The third line of code checks if the string ‘alpha;beta;gamma’ contains only alphabetic characters, which is False because it contains ‘;’.

lukaki
Nov 26, 2021

Answer C; #Example_1 the_list='alpha;beta;gamma'.split(":") print(the_list) the_string=''.join(the_list) print(the_string) print(the_string.isalpha()) # Output: # ['alpha;beta;gamma'] # alpha;beta;gamma # False #Example_2 the_list='alpha:beta:gamma'.split(":") print(the_list) the_string=''.join(the_list) print(the_string) print(the_string.isalpha()) # Output: # ['alpha', 'beta', 'gamma'] # alphabetagamma # True

sadako11
Feb 16, 2022

Another question with a possible typo. Is it supposed to be 'isalpha()' or 'isaplpha()'? Using 'isalpha()' gives a False and using 'isaplpha()' gives an error

carpmatiasOption: C
May 11, 2022

Only if there is a typo in 'isaplpha()' and it means actually 'isalpha()' the it's C

roncr
Nov 5, 2023

there is a typo, is ; instead of : so its B "true"

mazimir
Oct 15, 2021

It outputs: False. Because of .split(":") output of the_list is list with one element ["alpha;beta;gamma"]

Hrishi8888
Oct 29, 2021

The spelling if isalpha() is also wrong in code

Efren
Nov 13, 2021

C- False: the_list='alpha;beta;gamma'.split(":") >>> the_list ['alpha;beta;gamma'] >>> the_string=''.join(the_list) >>> the_string 'alpha;beta;gamma' >>> print(the_string.isalpha()) False

macxszOption: C
May 4, 2022

C. it outputs False

mplopezOption: A
Aug 27, 2023

Hi, check the code twice before give your answers. If you read correctly the code if you execute it you will see that as it's wrote the response is an exception, so the answer is A. Normally, you need to answer as you have in the questionnaire

BonesawOption: B
Feb 1, 2024

I agree with roncr, the ; should be : instead. Also isaplpha() should be isalpha(). Once those are corrected it returns True

Dave304409Option: C
Apr 15, 2025

is correct