forked from spierre91/medium_code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexception_handling.py
More file actions
42 lines (29 loc) · 907 Bytes
/
Copy pathexception_handling.py
File metadata and controls
42 lines (29 loc) · 907 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
40
41
import numpy as np
my_list1 = [1, 2, 3, 4, 5]
for value in my_list1:
print(value)
for value in my_list1:
square = value**2
print(value, square)
my_list2 = [1, 2, 3, 4, 5, '6']
for value in my_list2:
try:
square = value**2
print(value, square)
except(TypeError):
square = int(value)**2
print(value, square)
my_list3 = [1, 2, 3, 4, 5, '##']
for value in my_list3:
try:
square = value**2
print(value, square)
except(TypeError):
square = np.nan
print(value, square)
my_list4 = ['python c++ java', 'SQL R scala', 'pandas keras sklearn', {'language': 'golang ruby julia'}]
for value in my_list4:
try:
print([i +' is awesome' for i in value.split()])
except(AttributeError):
print([i +' is awesome' for i in value['language'].split()])