Questions for: Data Types
my_string = "Hello, World!"
result = my_string.count("l")
print(result)
count() method returns the number of occurrences of the specified substring in the string.my_dict = {'a': 1, 'b': 2, 'c': 3}
result = my_dict.keys()
print(result)
{'a', 'b', 'c'}['a', 'b', 'c']dict_keys(['a', 'b', 'c'])The keys() method in Python returns a view object that displays a list of all the keys in the dictionary.
In this case, it will return a view object containing the keys 'a', 'b', and 'c'. When printed, it shows as dict_keys(['a', 'b', 'c']). This is a view object, not a list, but it behaves similarly in many situations.
Discuss About this Question.
any() function?
FalseTrueNoneany() function returns True if at least one element in the iterable is True, otherwise False.Discuss About this Question.
my_string = "Hello, World!"
result = my_string.split()
print(result)
['Hello,', 'World!']'Hello, World!'('Hello', 'World!')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.
Discuss About this Question.
my_list = [4, 2, 7, 1, 9]
result = sorted(my_list)
print(result)
[1, 2, 4, 7, 9][9, 7, 4, 2, 1]TrueFalsesorted() function in Python returns a new sorted list from the elements of the given iterable, in this case, the list my_list. So, the elements of my_list will be sorted in ascending order, and the sorted list [1, 2, 4, 7, 9] will be printed.Discuss About this Question.
Discuss About this Question.