Friday, September 29, 2023

Generics in Python "Annotation Variables and Functions"

 def add(x: int, y: int) -> int:

    return x + y

annotation Variables:-
we can annotate a variable using ":" colon sign proceeding with the data type 

variable_name : data_type = value 

===============================
from typing import Optional

def get_name(prefix: Optional[str]) -> str:
    if prefix:
        return prefix + "John"
    return "John"
======================================

No comments:

Post a Comment

virtual environment on python on Ubuntu

 # 1. Update system and install Python tools sudo apt update && sudo apt install python3-pip python3-venv -y # 2. Setup Django in a ...