-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython.py
More file actions
41 lines (32 loc) · 816 Bytes
/
python.py
File metadata and controls
41 lines (32 loc) · 816 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
# Code snippets which can't really be expressed in unit test
# Throwing an exception
items = [1, 2]
if len(items) == 0:
raise ValueError("Empty list")
# Pass is a null operation (i.e. nothing happens). Useful to use temporarily as body for methods until they are fleshed
# out.
f = False
if f is True:
pass
else:
print("hello")
print("print line never gets called")
# _ can be used when you don't care about its value, e.g.
print()
for _ in range(5):
print("hello world")
# To create a custom exception class
class CustomError(Exception):
pass
# Creating a normal class
class A(object):
def __init__(self):
self.x = 'Hello'
self.y = 1
def add(self, arg: int):
self.y = self.y + arg
foo = A()
print(foo.x)
# Shows as error in IDE
foo.add("a")
print(foo.y)