Python Programming - Data Types - Discussion

Discussion Forum : Data Types - General Questions (Q.No. 62)
62.
What is the output of the following code snippet?
my_string = "Hello, World!"
result = my_string.split()
print(result)
['Hello,', 'World!']
'Hello, World!'
('Hello', 'World!')
Error
Answer: Option
Explanation:

The split() method in Python splits a string into a list of substrings based on a specified separator. If no separator is provided, it defaults to splitting the string by "whitespace".

In this case, since no separator is provided, the string my_string will be split into substrings based on whitespace, resulting in ['Hello,', 'World!'], which will be printed.

Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.