>>> header = "Say hello in Python" >>> >>> def hello(name: str) -> str: ... """ ... %s ... ... Python is amazing! ... """ ... return f"Hello {name}. Nice to meet you!" ... >>> hello.__doc__ %= header >>> help(hello) Help on function hello in module __main__: hello(name: str) -> str Say hello in Python Python is amazing! >>>
Python supports three different methods of string interpolation. Here they are:
• Using the %s method (the oldest)
• Using the format() string method
• Using f-strings