Python Dictionary Basic Operations|Dictionaries in Python| Dictionary

Опубликовано: 15 Май 2024
на канале: Sagar Nangare
14
1

Return a new dictionary initialized from an optional positional argument and a possibly empty set of keyword arguments.

Dictionaries can be created by several means:

Use a comma-separated list of key: value pairs within braces: {'jack': 4098, 'sjoerd': 4127} or {4098: 'jack', 4127: 'sjoerd'}

Use a dict comprehension: {}, {x: x ** 2 for x in range(10)}

Use the type constructor: dict(), dict([('foo', 100), ('bar', 200)]), dict(foo=100, bar=200)

If no positional argument is given, an empty dictionary is created. If a positional argument is given and it is a mapping object, a dictionary is made with the same key-value pairs as the mapping object. Otherwise, the positional argument must be an iterable object. Each item in the iterable must be an iterable with exactly two objects. The first object of each item becomes a key in the new dictionary, and the second object is the corresponding value. If a key occurs more than once, the last value for that key becomes the corresponding value in the new dictionary.

If keyword arguments are given, the keyword arguments and their values are added to the dictionary created from the positional argument. If a key being added is already present, the value from the keyword argument replaces the value from the positional argument.


На этой странице сайта вы можете посмотреть видео онлайн Python Dictionary Basic Operations|Dictionaries in Python| Dictionary длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь Sagar Nangare 15 Май 2024, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 14 раз и оно понравилось 1 зрителям. Приятного просмотра!