Last active
April 19, 2023 03:35
-
-
Save jeongukjae/56dabac5ae2d4f0bd2b160bc463daada to your computer and use it in GitHub Desktop.
Pythons snippet
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
list_var = [1, 2, 3] | |
# Same as list_var2 = list(map(lambda x: x+1, list_var)) | |
list_var2 = [elem + 1 for elem in list_var] | |
# same as list_var3 = list(filter(lambda x: x!=1, list_var)) | |
list_var3 = [elem for elem in list_var if elem != 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
# Tuple, immutable, ordered | |
a = (1,2,3) | |
# List, mutable, ordered | |
b = [1,2,3] | |
# Set, unordered | |
c = {1,2,3} | |
# Dict, key-value pair | |
d = {"first": 1, "second": 2} |
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
class A: | |
field1: str | |
def __init__(self, ...): | |
"""constructor""" | |
pass | |
def __del__(self): | |
"""Destructor""" | |
pass | |
def method1(self, ...): | |
"""definition of method""" | |
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
def fn_raising_error_if_val_is_one(val: int): | |
"""This function will raise error if val is one | |
Args: | |
val: input value | |
Returns: None | |
Raises: | |
ValueError: if val is one | |
""" | |
if val == 1: | |
raise ValueError("input param val shouldn't be one") | |
try: | |
fn_raising_error_if_val_is_one(1) | |
except ValueError as e: | |
print("ValueError is raised") | |
print(e) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment