Python Notes Set 2
Python Notes Set 2
- Write: file.write("text")
Example:
f.write("Hello, File!")
Page 2: Exception Handling
Try-Except:
try:
x=1/0
except ZeroDivisionError:
finally:
Nested:
s = {x for x in range(5)}
Lambda:
- Anonymous functions
add = lambda x, y: x + y
Map:
nums = [1, 2, 3]
Filter:
def decorator(func):
def wrapper():
print("Before")
func()
print("After")
return wrapper
@decorator
def say_hello():
print("Hello!")
say_hello()