Skip to content

VijayAIeng/Python-Type-Hints

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 

Repository files navigation

Python Type Hints & Typing Module Examples

A learning repository for Python type hints and the typing module.
This repo contains examples and explanations of common Python typing features like List, Tuple, Set, Dict, Union, Optional, Any, Callable, and more.


🔹 Features

  • Basic Python type hints (int, str, float, etc.)
  • Typing module examples:
    • List, Tuple, Set, Dict
    • Union, Optional, Any, Callable
  • Real-world examples:
    • Counting letters in a string
    • Using Callable for function parameters
    • Combining Union, Optional, and Any
  • Safe dictionary access using .get(), .keys(), .values(), .items()
  • List comprehensions and filtering examples
  • Step-by-step explanations for beginners

🔹 Example

from typing import List, Dict

def count_letters(word: str) -> Dict[str, int]:
    counts: Dict[str, int] = {}
    for letter in word:
        counts[letter] = counts.get(letter, 0) + 1
    return counts

print(count_letters("banana"))
# Output: {'b': 1, 'a': 3, 'n': 2}

About

A comprehensive collection of Python type hint examples and explanations, covering List, Tuple, Set, Dict, Union, Optional, Any, Callable, and more for beginners and intermediate learners.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors