Skip to content

Commit e5a30bb

Browse files
Assertion in Python(Debugging using assert statement),assert keyword.
1 parent c3e1720 commit e5a30bb

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Assertions.py

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#Assertion in Python
2+
#assert statement used for debugging
3+
#two types of assert statements 1.simple version(without message)2. augmented version(with message)
4+
#syntax: assert condition_expression,message
5+
#if condition false then AsserionError
6+
#To disable assert statements for client py -O test.py
7+
def square_it(x):
8+
return x*x
9+
10+
assert square_it(2)==4,'Here result must be 4 but it is not'
11+
assert square_it(3)==9,'Here result must be 9 but it is not'
12+
assert square_it(4)==16,'Here result must be 16 but it is not'
13+
14+
print(square_it(2))
15+
print(square_it(3))
16+
print(square_it(4))
17+
print(square_it(5))

0 commit comments

Comments
 (0)