CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
Avatar for Software 20.04.

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

| Download
Views: 140
Image: ubuntu2004-dev
Kernel: Python 3 (SageMath)

Python 3.10 inside the current version of Sage

import sys sys.executable
'/ext/sage/9.7/local/var/lib/sage/venv-python3.10.5/bin/python3'
sys.version
'3.10.5 (main, Sep 20 2022, 13:29:17) [GCC 9.4.0]'
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=}")
a='a' b=1 c=[5, 1]
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()
Image in a Jupyter notebook

Merge/Update Dicts:

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

String Methods

"foo-bar".removesuffix("bar")
'foo-'
from zoneinfo import ZoneInfo from datetime import datetime, timedelta dt = datetime(2020, 10, 31, 12, tzinfo=ZoneInfo("America/Los_Angeles")) dt
datetime.datetime(2020, 10, 31, 12, 0, tzinfo=zoneinfo.ZoneInfo(key='America/Los_Angeles'))
dt += timedelta(days=7) dt
datetime.datetime(2020, 11, 7, 12, 0, tzinfo=zoneinfo.ZoneInfo(key='America/Los_Angeles'))
print(dt.tzname())
PST
import matplotlib.pyplot as plt plt.plot([12,3,2,3,2,3,1])
[<matplotlib.lines.Line2D at 0x7f62b831a230>]
Image in a Jupyter notebook