'Salma') say_hello(
'Hello Salma!'
say_hello (to)
Say hello to somebody
say_goodbye (to)
Say goodbye to somebody
Person (name:str, age:int)
A dummy class to test.
We can make the documentation nicer by adding a comment to each parameter that then get nicely rendered by nbdev
Person2 (name:str, age:int)
A dummy class to test.
Type | Details | |
---|---|---|
name | str | a person’s name |
age | int | a person’s age |
To see where some func / obj comes from:
Signature: show_doc( sym, renderer=None, name: 'str | None' = None, title_level: 'int' = 3, ) Docstring: Show signature and docstring for `sym` File: ~/workspace/envs/claude-env/lib/python3.13/site-packages/nbdev/showdoc.py Type: function
Signature: say_hello(to) Source: def say_hello(to): "Say hello to somebody" return f"Hello {to}!" File: /var/folders/9p/5ycxgmps44zc3f0y6vljhp2h0000gn/T/ipykernel_46397/180399582.py Type: function
In other languages like C++, u can define methods outside their class. In Python, we can use a util from fastcore to do so:
This gives us a @patch
decorator
Person.__eq__ (other:__main__.Person)
Return self==value.
Why do this?
This allows us to group same functionalities together eg all comparison operators in one place
Person.__lt__ (other:__main__.Person)
Return self<value.
Person.__gt__ (other:__main__.Person)
Return self>value.