Skip to content

Instantly share code, notes, and snippets.

def quotient(dividend, divisor, taking_int=False):
"""
Calculate the product of two numbers with a base factor.
:param dividend: int | float, the dividend in the division
:param divisor: int | float, the divisor in the division
:param taking_int: bool, whether only taking the integer part of the quotient;
default: False, which calculates the precise quotient of the two numbers
:return: float | int, the quotient of the dividend and divisor
def example_fun(param0, param1):
"""
Does what
Args:
param0:
param1:
Returns:
Describe the return value
def example_fun(param0, param1):
"""
Does what
:param param0:
:param param1:
:return:
:raises:
def multiplier(num1: float, num2: float) -> float:
"""Multiply two numbers to get their product.
:param num1: float, first number for multiplication
:param num2: float, second number for multiplication
:return: float, the product of the two numbers
"""
return num1 * num2
class Student:
def __init__(self, name, age):
self.name = name
self.age = age
def __repr__(self):
return f"Student({self.name!r}, {self.age})"
def __str__(self):
return f"Student Name: {self.name}; Age: {self.age}"
class Student:
def __init__(self, name, age):
self.name = name
self.age = age
def __repr__(self):
return "Student __repr__ string"
def __str__(self):
return "Student __str__ string"
>>> name = "Danny"
>>> age = 15
>>> student = {"name": name}
>>> scores = [100, 99, 95]
>>> location = ('123 Main', 'NY')
>>> for item in (name, age, student, scores, location):
... print(f"{type(item)!s: <15}| repr: {repr(item): <20}| str: {str(item)}")
...
<class 'str'> | repr: 'Danny' | str: Danny
<class 'int'> | repr: 15 | str: 15
>>> data = {"timestamp": ["01/01/2022 09:01:00", "01/02/2022 08:55:44", "05/01/2022 22:01:00"],
... "category": list('ABC')}
>>> df = pd.DataFrame(data)
>>> df.dtypes
timestamp object
category object
dtype: object
>>> df["timestamp"] = pd.to_datetime(df["timestamp"])
>>> df.dtypes
timestamp datetime64[ns]
>>> pd.date_range(start="12/01/2022", end="12/07/2022")
DatetimeIndex(['2022-12-01', '2022-12-02', '2022-12-03', '2022-12-04',
'2022-12-05', '2022-12-06', '2022-12-07'],
dtype='datetime64[ns]', freq='D')
>>> import datetime
>>> start_date = datetime.datetime(2022, 12, 1)
>>> one_week = [start_date + datetime.timedelta(days=x) for x in range(7)]
>>> pd.DatetimeIndex(one_week)
DatetimeIndex(['2022-12-01', '2022-12-02', '2022-12-03', '2022-12-04',
'2022-12-05', '2022-12-06', '2022-12-07'],
dtype='datetime64[ns]', freq=None)