python / beginner
Snippet
Basic Variable Type Hints
Type hints allow you to specify the expected data type of a variable or function parameter. While Python doesn't strictly enforce them at runtime, they make the code much easier for humans to read and for editors to check.
snippet.py
1
2
3
4
5
username: str = "coder123"score: int = 500def greet(name: str):print("Hello", name)
Breakdown
1
username: str = "coder123"
Declares that the variable 'username' should specifically be a string.
2
def greet(name: str):
Indicates that the 'name' parameter for this function is expected to be a string.