PCAP Exam QuestionsBrowse all questions from this exam

PCAP Exam - Question 52


How many elements will the list1 list contain after execution of the following snippet?

Show Answer
Correct Answer: A

The split() method in Python divides a string into a list using a specified separator. In this case, the string "don't think twice, do it!" is split using a comma (',') as the separator. This results in two parts: "don't think twice" and " do it!", which become the elements of the list. Hence, the list1 will contain two elements after executing the given code snippet.

Discussion

13 comments
Sign in to comment
AvidulamOption: A
Mar 12, 2020

There will be two elements, the answer should be A

LearningOnlyWayOption: A
Apr 23, 2020

correct answer is A almost 20% answers are wrong on this site

Tarun1
Mar 9, 2020

this is wrong

AmritanshOption: A
Jun 8, 2020

List1 = "don't think twice, do it!".split(',') print(List1) ["don't think twice", ' do it!'] correct answer is A which is two

OnsYedesOption: A
Oct 17, 2020

list="don't think twice, do it!".split(',') print(len(list)) output===>2

imsaadOption: A
Jul 24, 2020

Answer should be A

AEscajedaOption: B
Jun 28, 2021

Actually list1 doesnt exist, the definition is List1.

TheFivePipsOption: C
Dec 6, 2023

string.split(separator, maxsplit) separator : Optional. Specifies the separator to use when splitting the string. By default any whitespace is a separator maxsplit : Optional. Specifies how many splits to do. Default value is -1, which is "all occurrences"

SpectraOption: A
Sep 5, 2020

2 elements

themeisterOption: A
May 12, 2021

A is correct.

JyotishriOption: A
Jun 1, 2021

Answer should be A

macxszOption: A
May 3, 2022

answer: A. two

Ello2023Option: A
Jun 15, 2023

It prints ['don't think twice', ' do it!']