There are four different literal collections List literals, Tuple literals, Dict literals, and Set literals.
Example 10: How to use literals collections in Python?
fruits = ["apple", "mango", "orange"] #list
numbers = (1, 2, 3) #tuple
alphabets = {'a':'apple', 'b':'ball', 'c':'cat'} #dictionary
vowels = {'a', 'e', 'i' , 'o', 'u'} #set
print(fruits)
print(numbers)
print(alphabets)
print(vowels)
Output
['apple', 'mango', 'orange'] (1, 2, 3) {'a': 'apple', 'b': 'ball', 'c': 'cat'} {'e', 'a', 'o', 'i', 'u'}
In the above program, we created a list of fruits, a tuple of numbers, a dictionary dict having values with keys designated to each value and a set of vowels
No comments:
Post a Comment