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
x = 'foo' | |
y = x | |
print x # foo | |
y += 'bar' | |
print x # foo | |
x = [1, 2, 3] | |
y = x | |
print x # [1, 2, 3] | |
y += [3, 2, 1] |
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
x = something # immutable type | |
print x | |
func(x) | |
print x # prints the same thing | |
x = something # mutable type | |
print x | |
func(x) | |
print x # might print something different |
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
#The @ symbol indicates that we are applying | |
#the decorator to the function hello() | |
@timer | |
def hello(): | |
pass |
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
#The @ symbol indicates that we are applying the decorator to | |
#the function hello() | |
@timer | |
def hello(): | |
pass |
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
#Code For decorator | |
import timeit | |
import logging | |
def timer(func): | |
def wrap(*args, **kwargs): | |
started_at = time.time() | |
result = func(*args, **kwargs) | |
logging.info(time.time() - started_at) |