-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbasic-functions.py
More file actions
35 lines (29 loc) · 891 Bytes
/
basic-functions.py
File metadata and controls
35 lines (29 loc) · 891 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# Functions
# This script explains how to define and use functions in Python.
# Defining a function
def greet(name):
"""
This function takes a name as input and prints a greeting.
"""
print("Hello, " + name + "!")
# Calling a function
greet("Alice") # This will output: Hello, Alice!
greet("Bob") # This will output: Hello, Bob!
# Functions can also return values
def add(a, b):
"""
This function takes two numbers as input and returns their sum.
"""
return a + b
# Using the return value of a function
result = add(3, 5)
print(result) # This will output: 8
# Another example of a function that returns a value
def multiply(x, y):
"""
This function takes two numbers as input and returns their product.
"""
return x * y
# Using the return value of the multiply function
product = multiply(4, 6)
print(product) # This will output: 24