Ask
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News Sign UpSign In
Views: 89
Image: ubuntu2004-dev
Embed | Download | Raw |
Kernel: Python 3 (SageMath)

Python 3.10 inside the current version of Sage

import sys sys.executable
sys.version
def func(num: int | float) -> int | float: return num + 5

structural matching

p = ('a', 1, 5, 1) #p = "asdf" match p: case None: print("none") case (1, b, *c): print(f"a is one and {b=} {c=}") case (a, b, *c): print(f"{a=} {b=} {c=}") case _: print(f"{p=}")
import numpy as np import matplotlib.pyplot as plt xx = np.linspace(0, 10, 1000) yy = np.sin(2.3 * np.exp(-xx)) plt.plot(xx, yy) plt.show()

Merge/Update Dicts:

x = {"a": 123, "b": 9} y = {"foo": "bar"} x | y

String Methods

"foo-bar".removesuffix("bar")
from zoneinfo import ZoneInfo from datetime import datetime, timedelta dt = datetime(2020, 10, 31, 12, tzinfo=ZoneInfo("America/Los_Angeles")) dt
dt += timedelta(days=7) dt
print(dt.tzname())
import matplotlib.pyplot as plt plt.plot([12,3,2,3,2,3,1])