How do you communicate via code what argument types and what return value type a function has?
Experience Level: Junior
Tags: Python
Answer
Always use type hints.
Example:
def get_messages(template: str, number: int) -> list[str]:
message1 = "Message template: " + template
message2 = "Number: " + str(number)
return [message1, message2]
print(get_messages("Hello", 1))
# This will print ['Message template: Hello', 'Number: 1']
Related Python job interview questions
What is a convention to name a protected method in Python?
Python JuniorWhat is a convention to name a private method in Python?
Python JuniorHow do you define a function in Python?
Python JuniorHow can you display all modules that are currently loaded in your Python program?
Python JuniorWhat happens if you import a same module in Python twice and the module contains code print("hello")?
Python Junior
Chat
Oh, the operator is not available. Leave us your comments. We will answer all your questions as soon as possible.
Anonymous
Καλησπέρα.
Καλησπέρα.
Anonymous
the infinteis -3/15 so 1triition / infinet
the infinteis -3/15 so 1triition / infinet
Anonymous
e
e
Anonymous
<a href="https://inspirum.pl "
<a href="https://inspirum.pl "
Anonymous
[url]https://inspirum.pl[/url]
[url]https://inspirum.pl[/url]
LaceJaguar65
e
e
LaceJaguar65
e
e
LaceJaguar65
e
e
LaceJaguar65
e
e
LaceJaguar65
e
e
LaceJaguar65
e
e
LaceJaguar65
e
e
LaceJaguar65
e
e
LaceJaguar65
e
e
LaceJaguar65
e
e
LaceJaguar65
e
e
LaceJaguar65
e
e
LaceJaguar65
e
e
LaceJaguar65
e
e
LaceJaguar65
e
e
LaceJaguar65
e
e
LaceJaguar65
e
e
LaceJaguar65
e
e
LaceJaguar65
e
e
LaceJaguar65
e
e