1. Home
  2. /
  3. Python
  4. /
  5. Function with Optional Argument

Function with Optional Argument - Python Typing CST Test

Loading…

Function with Optional Argument — Python Code

Defining a function with an optional parameter and default value.

def greet(name: str, greeting: Optional[str] = "Hello") -> None:
	print(f"{greeting}, {name}!")

greet("Alice")
greet("Bob", greeting="Hi")

Python Language Guide

Python is a high-level, dynamically typed, multi-paradigm programming language known for simplicity, readability, and massive ecosystem support. It powers web development, data science, machine learning, automation, scripting, backend systems, and more.

Primary Use Cases

  • ▸Backend web development
  • ▸Machine learning & AI
  • ▸Data analysis & visualization
  • ▸Automation & scripting
  • ▸API development
  • ▸Scientific computing
  • ▸DevOps tooling
  • ▸Cybersecurity scripting

Notable Features

  • ▸Simple, readable syntax
  • ▸Massive standard library
  • ▸Dynamically typed
  • ▸Extensive third-party ecosystem (PyPI)
  • ▸Cross-platform
  • ▸Strong scientific & ML libraries

Origin & Creator

Created by Guido van Rossum in 1991, inspired by ABC language with a vision of a simple, readable language for everyday programming tasks.

Industrial Note

Python dominates in AI/ML research, automation-heavy engineering teams, fast MVP prototyping, data-driven industries, hybrid cloud pipelines, ETL scripting, scientific computing, and large-scale analytical workflows.

More Python Typing Exercises

Python List Comprehension and FunctionsPython Quick Sort AlgorithmPython Dictionary ComprehensionsPython Filter and MapPython Lambda and ReducePython Set ComprehensionPython Nested List ComprehensionPython Zip FunctionPython List Comprehension with ConditionPython Recursion Example

Practice Other Languages

CReactC++RustTypeScriptKotlinPHPJavaC#RubyMqlCqlN1qlCypherGremlin