Skip to content

Type hint arrow samples #679

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 43 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
06b4238
Create ->-in-function-definitions
dphoenix Jun 24, 2025
4f7e271
Create simple_type_hint_example.py
dphoenix Jun 24, 2025
def2f9e
Add files via upload
dphoenix Jun 24, 2025
d5924a2
Update str_return_type_hint_example.py
dphoenix Jun 24, 2025
035ba13
Update str_return_type_hint_example.py
dphoenix Jun 24, 2025
726066f
Update str_return_type_hint_example.py
dphoenix Jun 24, 2025
e05ec45
Update str_return_type_hint_example.py
dphoenix Jun 24, 2025
53e11d8
Update str_return_type_hint_example.py
dphoenix Jun 24, 2025
e9688a7
Update simple_type_hint_example.py
dphoenix Jul 5, 2025
9ff41d9
Update str_return_type_hint_example.py
dphoenix Jul 6, 2025
c5a15ad
Update str_return_type_hint_example.py
dphoenix Jul 6, 2025
5fc9bc5
Update str_return_type_hint_example.py
dphoenix Jul 6, 2025
3b9b2a1
Update str_return_type_hint_example.py
dphoenix Jul 6, 2025
3e3280e
Update str_return_type_hint_example.py
dphoenix Jul 6, 2025
4066631
Update str_return_type_hint_example.py
dphoenix Jul 6, 2025
706cfd5
Update dictionary_return_type_example.py
dphoenix Jul 6, 2025
5b0e6e3
Update dynamic_variable_example.py
dphoenix Jul 6, 2025
9361978
Update game_class_example.py
dphoenix Jul 6, 2025
41d957a
Update mismatched_return_type_example.py
dphoenix Jul 6, 2025
32eb171
Update none_return_type_hint_example.py
dphoenix Jul 6, 2025
00a783b
Update simple_type_hint_example.py
dphoenix Jul 6, 2025
3c3890b
Update mismatched_return_type_example.py
dphoenix Jul 6, 2025
22e4941
Update none_return_type_hint_example.py
dphoenix Jul 6, 2025
3b24397
Update mismatched_return_type_example.py
dphoenix Jul 6, 2025
b841a72
Update simple_type_hint_example.py
dphoenix Jul 6, 2025
43a430d
Update simple_type_hint_example.py
dphoenix Jul 6, 2025
eb9d01d
Update none_return_type_hint_example.py
dphoenix Jul 6, 2025
6f4da87
Update mismatched_return_type_example.py
dphoenix Jul 6, 2025
b29e42a
Update simple_type_hint_example.py
dphoenix Jul 6, 2025
d7a5f89
Update simple_type_hint_example.py
dphoenix Jul 6, 2025
184ca23
Update simple_type_hint_example.py
dphoenix Jul 6, 2025
5a6b4b7
Update simple_type_hint_example.py
dphoenix Jul 6, 2025
2d43c10
Update str_return_type_hint_example.py
dphoenix Jul 6, 2025
e637607
Update mismatched_return_type_example.py
dphoenix Jul 6, 2025
02f2099
Update mismatched_return_type_example.py
dphoenix Jul 6, 2025
31f97ef
Renamed samples folder and added a README file
dphoenix Jul 6, 2025
8eb6648
Update README.md
dphoenix Jul 6, 2025
1ecf12d
Update game_class_example.py
dphoenix Jul 7, 2025
9f43b13
Update dictionary_return_type_example.py
dphoenix Jul 7, 2025
c0862ad
Update simple_type_hint_example.py
dphoenix Jul 10, 2025
8cce0b7
Update str_return_type_hint_example.py
dphoenix Jul 10, 2025
7fa9ff3
Update none_return_type_hint_example.py
dphoenix Jul 10, 2025
835a5ac
Update mismatched_return_type_example.py
dphoenix Jul 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ->-in-function-definitions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

2 changes: 2 additions & 0 deletions type-hint-arrow-samples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
What Does -> Mean in Python Function Definitions?
This folder provides the code examples for the Real Python tutorial [What Does -> Mean in Python Function Definitions?](https://realpython.com/what-does-mean-in-python-function-definitions/)
18 changes: 18 additions & 0 deletions type-hint-arrow-samples/dictionary_return_type_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
game_stock = {"Dragon Quest": 5, "Final Fantasy": 1, "Age of Empires": 5}


def get_highest_stock_games() -> dict[str, int]:
stock_quantities = game_stock.values()
high = 0
for quantity in stock_quantities:
if quantity > high:
high = quantity
game_results = {}

for game in game_stock:
if game_stock[game] == high:
game_results[game] = high
return game_results


print(f"Games with the highest stock: {get_highest_stock_games()}")
2 changes: 2 additions & 0 deletions type-hint-arrow-samples/dynamic_variable_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
my_number = 32
my_number = "32"
14 changes: 14 additions & 0 deletions type-hint-arrow-samples/game_class_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class Game:
def __init__(self, name: str, genre: str, price: float) -> None:
self.name = name
self.genre = genre
self.price = price

def get_name(self) -> str:
return self.name

def get_genre(self) -> str:
return self.genre

def get_price(self) -> float:
return self.price
6 changes: 6 additions & 0 deletions type-hint-arrow-samples/mismatched_return_type_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
def get_number_of_titles(titles: list) -> str:
return len(titles)


games = ["Dragon Quest", "Final Fantasy", "Age of Empires"]
print(f"Number of titles: {get_number_of_titles(games)}")
9 changes: 9 additions & 0 deletions type-hint-arrow-samples/none_return_type_hint_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
def find_keyword_in_titles(titles: list, keyword: str) -> None:
print(f"Titles that contain the keyword {keyword}")
for game_title in titles:
if keyword in game_title:
print(f"{game_title}")


games = ["Dragon Quest", "Final Fantasy", "Age of Empires"]
find_keyword_in_titles(games, "Final")
6 changes: 6 additions & 0 deletions type-hint-arrow-samples/simple_type_hint_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
def get_number_of_titles(titles: list) -> int:
return len(titles)


games = ["Dragon Quest", "Final Fantasy", "Age of Empires"]
print(f"Number of titles: {get_number_of_titles(games)}")
9 changes: 9 additions & 0 deletions type-hint-arrow-samples/str_return_type_hint_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import random


def get_game_recommendation(titles: list) -> str:
return random.choice(titles)


games = ["Dragon Quest", "Final Fantasy", "Age of Empires"]
print(f"Random recommendation: {get_game_recommendation(games)}")