LuminousHub

Python Comments, def Functions And input() Function: Basic Notes

1. Comments

Definition: Comments are lines of text within a Python program that are ignored by the interpreter. They help explain code.

Types:

# This is a single-line comment
"""
This is a multi-line comment.
"""

2. def Functions

Definition: A function in Python is a flexible, reusable block of code designed to perform specific tasks. You define it using the def keyword, allowing you to call it multiple times with different inputs for efficient and organized coding.

Syntax:

def function_name(parameters):
    # Function body
    return value

Example:

def greet(name):
    return f"Hello, {name}!"

print(greet("AH Developer"))

3. input() Function

Definition: The input() function takes user input as a string.

Syntax:

input(prompt)

Example:

user_input = input("Enter your name: ")
print(f"Hello, {user_input}!")