-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Labels
Description
for loops
I'm used to
List.filterso getting used toforloops again takes time.
Make sure you've exited the loop before raising an exception!
new_list = []
def loop(list):
for item in list:
if item == 3:
new_list.append(item)
# The correct indentation is OUTSIDE the loop,
# not within the `if` or `for` loop.
raise HTTPException(
status_code=404,
detail="Item with number 3 was not found"
) if statements
In Elm you have must use the
elsekeyword.
It's optional in Python.
def has_three(list):
if len(list) == 3:
return "Yes!"
return "No!"Using classes
You can use
.dot notation to access fields ...
Dictionaries requiredict["key"](string accessors)
from pydantic import BaseModel
from typing import Optional
class Item(BaseModel):
id: int
name: Optional[str]
item = Item(id=1)
item.id # returns 1