forked from makelinux/examples
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3.9.py
More file actions
Latest commit
executable file
·39 lines (22 loc) · 886 Bytes
/
Copy path3.9.py
File metadata and controls
executable file
·39 lines (22 loc) · 886 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env python3.9
frompassedimportpassed
# https://docs.python.org/3.9/whatsnew/3.9.html
# https://docs.python.org/3.9/whatsnew/3.9.html#dictionary-merge-update-operators
dict_1= {'a': 0, 'b': 2}
dict_2= {'a': 1, 'c': 3}
# Merging dictionaries
assertdict_1|dict_2== {'a': 1, 'b': 2, 'c': 3}
dict_1|=dict_2
# Updating a dictionary
assertdict_1|dict_2== {'a': 1, 'b': 2, 'c': 3}
assertdict_1== {'a': 1, 'b': 2, 'c': 3}
# In type annotations you can now use built-in collection types such as list
# and dict as generic types instead of importing the corresponding
# capitalized types.
# https://docs.python.org/3.9/whatsnew/3.9.html#pep-585-builtin-generic-types
defis_list(a_list: list[int]) ->bool:
returnisinstance(a_list, list)
assertis_list([1, 2, 3])
assert'ab'.removeprefix('a') =='b'
assert'ab'.removesuffix('b') =='a'
passed()