Python Collections: Lists, Tuples, Sets, and Dictionaries
"collect()" is not a built-in function in Python. To create collections like lists, tuples, sets, and dictionaries, you can use the following functions: "list()", "tuple()", "set()", and "dict()" respectively. Here are some examples: "list()" function: my_list = list([1, 2, 3, 4, 5]) print(my_list) # Output: [1, 2, 3, 4, 5] "tuple()" function: my_tuple = tuple((1, 2, 3, 4, 5)) print(my_tuple) # Output: (1, 2, 3, 4, 5) "set()" function: my_set = set({1, 2, 3, 4, 5}) print(my_set) # Output: {1, 2, 3, 4, 5} "dict()" function: my_dict = dict({'name': 'John', 'age': 25}) print(my_dict) # Output: {'name': 'John', 'age': 25}
原文地址: https://www.cveoy.top/t/topic/pInQ 著作权归作者所有。请勿转载和采集!