Statements¶
Function Definitions¶
LisPy version
(deco [decorator1
decorator2]
(def function-name [arg1 arg2 *args :kwarg1 value1 :kwarg2 value2 **kwargs]
"docstring"
body1
body2
(return value)))
@decorator1
@decorator2
def function_name(arg1, arg2, *args, kwarg1=value1, kwarg2=value2, **kwargs):
"""docstring"""
body1
body2
return value
Async Function Definitions¶
Use async-def instead of def.
Class Definition¶
LisPy version
Python versiondel¶
LisPy version
Python versionAssignment¶
LisPy version
Python versionAugmented Assignment¶
LisPy version
Python versionType Annotations¶
Simple Type Annotations¶
LisPy version
Python versionAssignment with Type Annotations¶
LisPy version
Python versionFunction Definition with Type Annotations¶
LisPy version
Python versionPydantic Example¶
LisPy version
(class User [BaseModel]
(= id ^int)
(= name ^str "John Doe")
(= signup_ts ^(| datetime None))
(= tastes ^(sub dict (, str PositiveInt))))
class User(BaseModel):
id: int
name: str = "John Doe"
signup_ts: datetime | None
tastes: dict[str, PositiveInt]
for¶
LisPy version
Python versionAsynchronous for¶
Use async-for instead of for.
while¶
LisPy version
Python versionif¶
LisPy version
Python versiondo block¶
If you want to use multiple statements in then-body or else-body, you can use do block.
LisPy version
with¶
Simple with¶
LisPy version
Python versionwith with alias¶
LisPy version
Python versionAsynchronous with¶
Use async-with instead of with.
match¶
LisPy version
(match x
(case "Relevant"
...)
(case None
...)
(case [1 2]
...)
(case [1 2 *rest]
...)
(case [*_]
...)
(case {1 _ 2 _}
...)
(case {**rest}
...)
(case (Point2D 0 0)
...)
(case (Point3D :x 0 :y 0 :z 0)
...)
(case [x] as y
...)
(case _
...)
(case (| [x] y)
...))
match x:
case "Relevant":
...
case None:
...
case [1, 2]:
...
case [1, 2, *rest]:
...
case [*_]:
...
case {1: _, 2: _}:
...
case {**rest}:
...
case Point2D(0, 0):
...
case Point3D(x=0, y=0, z=0):
...
case [x] as y:
...
case _:
...
case [x] | y:
...
raise¶
LisPy version
Python versiontry¶
LisPy version
(try
body1
body2
(except [Exception1]
body3
body4)
(except [Exception2 as e]
body5
body6)
(else
body7
body8)
(finally
body9
body10))
try:
body1
body2
except Exception1:
body3
body4
except Exception2 as e:
body5
body6
else:
body7
body8
finally:
body9
body10
except* clause¶
LisPy version
Python versionassert¶
LisPy version
Python versionimport¶
Simple import¶
LisPy version
Python versionfrom import¶
without alias¶
LisPy version
Python versionwith alias¶
LisPy version
Python versionglobal¶
LisPy version
Python versionnonlocal¶
LisPy version
Python versionpass¶
LisPy version
Python versionbreak¶
LisPy version
Python versioncontinue¶
LisPy version
Python version