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
my_list = ['some', 'list', 'containing', 'five', 'elements'] | |
min_len = 3 | |
no_break = True | |
for element in my_list: | |
if len(element) < min_len: | |
print(f'Caught an element shorter than {min_len} letters') | |
no_break = False | |
break |
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
import numpy as np | |
a = np.arange(16).reshape(2,2,2,2) | |
print(a[..., 0].flatten()) | |
print(a[:, :, :, 0].flatten()) |
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
# calculate nth odd number | |
def nth_odd(n): | |
if isinstance(n, int): | |
return 2 * n - 1 | |
else: | |
return None | |
# calculate the original n of nth odd number | |
def original_num(m=...): |
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
def some_function(): | |
... | |
def another_function(): | |
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
a = 3 | |
b = eval('a + 2') | |
print('b =', b) | |
exec('c = a ** 2') | |
print('c is', c) |
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
a = 3250 | |
b = 67_543_423_778 | |
print(type(a)) | |
print(type(b)) | |
print(type(a)==type(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
def func(x): | |
intermediate_var = x**2 + x + 1 | |
if intermediate_var % 2: | |
y = intermediate_var ** 3 | |
else: | |
y = intermediate_var **3 + 1 | |
# setting attributes here | |
func.optional_return = intermediate_var |
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
my_list = ['some', 'list', 'containing', 'five', 'elements'] | |
min_len = 3 | |
for element in my_list: | |
if len(element) < min_len: | |
print(f'Caught an element shorter than {min_len} letters') | |
break | |
else: | |
print(f'All elements at least {min_len} letters long') |