FUNDAMENTALS OF COMPUTER

DATABASE FUNDAMENTALS

DATA WAREHOUSING AND DATA MINING

Question [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
What is the output of the following code in Python? my ____ new ____ string = “Go for best” print([i for j in my ____ new ____ string.split() for i in (j, ‘ ‘)][:-1])
A
[’Go’, ‘ ‘, ‘for’, ‘ ‘, ‘best’]
B
[’ ‘, ‘Go’, ‘ ‘, ‘for’, ‘ ‘, ‘best’, ‘ ‘]
C
[ ]
D
None
E
Error
Explanation: 

Detailed explanation-1: -Splitting a String by newline character () You can split a string using the newline character () in Python. We will take a string which will be separated by the newline character and then split the string. The newline character will act as the separator in the Split function.

Detailed explanation-2: -Definition and Usage. The split() method splits a string into a list. You can specify the separator, default separator is any whitespace. Note: When maxsplit is specified, the list will contain the specified number of elements plus one.

Detailed explanation-3: -Using split() and join() methods The split() method will break the given string by the specified separator and return a list of strings. The str separator is used by the join() method to connect the elements of a sequence into a string.

There is 1 question to complete.