no way to compare when less than two revisions
تفاوتها
تفاوت دو نسخهٔ متفاوت از صفحه را مشاهده میکنید.
— | courseware:python_programming:resources:code:23 [2022/07/19 17:51] (فعلی) – ایجاد شد - ویرایش خارجی 127.0.0.1 | ||
---|---|---|---|
خط 1: | خط 1: | ||
+ | ===== مثالهایی از کار با دیکشنری ===== | ||
+ | <code python line-numbers=" | ||
+ | # dict declaration | ||
+ | empty_dict = dict() | ||
+ | another_empty_dict = {} | ||
+ | |||
+ | people = { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | } | ||
+ | people[" | ||
+ | |||
+ | print(list(people.keys())) | ||
+ | print(list(people.values())) | ||
+ | |||
+ | for person_k, person_v in people.items(): | ||
+ | print(person_k, | ||
+ | |||
+ | # You can't use a list as a dict key in python because it's mutable | ||
+ | mydict = {[1, 2, 3]: ' | ||
+ | |||
+ | # But these lines of code are Ok: | ||
+ | mydict = {(1, 2, 3): [1, 2, 3], ' | ||
+ | mydict = {' | ||
+ | </ |