-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Assert & list Comprehension has been explained.
- Loading branch information
Showing
2 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# In this lets see about the assert in the python. | ||
|
||
# Assert is a kwyword used to define a debugging tool which is used to test a condition. | ||
|
||
# If the condition is true then it moves to the next line. | ||
|
||
# If the condition becomes false then it will be resulting in an AssertionError. | ||
|
||
# Syntac for assert is: | ||
|
||
# assert condition,error_message | ||
|
||
# condition = Condition to be checked. | ||
|
||
# error_message = error message to be displayed , which is optional. | ||
|
||
# Here is the example for assert | ||
|
||
a = int(input('\nEnter value of "a" : ')) | ||
|
||
b = int(input('\nEnter value of "b" : ')) | ||
|
||
assert b != 0,'Divisor 0 error' | ||
|
||
print('\na / b is : ',a/b) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# In this list comprehension has been explained. | ||
|
||
# List Comprehension is defined as an elegant way to define. | ||
|
||
# The list comprehension starts with '[' and ']'. | ||
|
||
# [ expression for item in list if conditional ] | ||
|
||
# Here is the program for list comprehension. | ||
|
||
List = [data for data in range(1,11)] | ||
|
||
print() # empty line for readability. | ||
|
||
print(List) | ||
|
||
print() # empty line for readability. |