Skip to content

Commit 4e766be

Browse files
committed
add assert_tutorial
1 parent 5ada909 commit 4e766be

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ Python Notes 學習筆記 📝
1818

1919
[repr_tutorial.py](https://github.com/twtrubiks/python-notes/blob/master/repr_tutorial.py) - repr tutorial
2020

21+
[assert_tutorial.py](https://github.com/twtrubiks/python-notes/blob/master/assert_tutorial.py) - assert tutorial
22+
2123
[str_find_tutorial.py](https://github.com/twtrubiks/python-notes/blob/master/str_find_tutorial.py) - str_find tutorial
2224

2325
[attribute_obj.py](https://github.com/twtrubiks/python-notes/blob/master/attribute_obj.py) - setattr() , getattr() , hasattr()

assert_tutorial.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
def ex1():
3+
4+
x = "hello"
5+
6+
# returns True, then nothing happens
7+
assert x == "hello"
8+
9+
# raise AssertionError
10+
assert x == "world"
11+
12+
def ex2():
13+
14+
x = "hello"
15+
assert x == "world", "x should be 'hello'"
16+
17+
if __name__ == "__main__":
18+
ex1()
19+
# ex2()
20+

0 commit comments

Comments
 (0)