Skip to content

Instantly share code, notes, and snippets.

Shivam Tiwari ShivamPsit

Block or report user

Report or block ShivamPsit

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@ShivamPsit
ShivamPsit / generator.py
Last active Sep 6, 2019
Generator in Python
View generator.py
# Generators don't hold entire result in the memory instead
# it yields one result at a time and
# takes less memory and time to execute
def cube_num(num):
for i in num:
yield(i)
# Create Generator by using Comprehension :
@ShivamPsit
ShivamPsit / exception_handling.py
Last active Sep 6, 2019
Exception_Handling_Python
View exception_handling.py
# If line 4 throw error, line 5 will not execute
# and only it will throw
try:
f = open('file.txt') # If file didn't found this line will throw 'FileNotFoundError'
m = any_var # This line will throw 'NameError'
except FileNotFoundError as e:
print(e)
except NameError as e:
print(e)
You can’t perform that action at this time.