0% found this document useful (0 votes)
3 views

Function in Python

The document provides an overview of user-defined functions in Python, detailing three types: functions without arguments, functions with arguments, and functions that return values. It includes syntax examples for each type and lists 15 solvable questions to practice writing these functions. Each question aims to reinforce the concepts of function creation and usage in Python.

Uploaded by

since2024gaming
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Function in Python

The document provides an overview of user-defined functions in Python, detailing three types: functions without arguments, functions with arguments, and functions that return values. It includes syntax examples for each type and lists 15 solvable questions to practice writing these functions. Each question aims to reinforce the concepts of function creation and usage in Python.

Uploaded by

since2024gaming
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

User-defined Functions in Python

1. Function without Argument


A function that does not take any arguments.

Syntax:

def function_name():
Code to execute
print("This is a function without arguments")

Example :

2. Function with Argument


A function that takes one or more arguments.

Syntax:

def function_name(arg1, arg2):


Code to execute
print(f"Arguments passed: {arg1}, {arg2}")

Example:
3. Function Returning Value
A function that returns a value after execution.

Syntax:

def function_name(arg1, arg2):


Code to execute
return arg1 + arg2
Example:

10 Solvable Questions

Function without Argument


1. Write a function to print "Hello, World!".
2. Write a function to display your name.
3. Write a function to print the multiplication table of 5.
4. Write a function to display the current date and time.
5. Write a function to print a pattern like:

Function with Argument


6. Write a function to take two numbers as input and print their sum.
7. Write a function to take a string as input and print it in reverse.
8. Write a function to take a list of numbers as input and print the maximum value.
9. Write a function to take a number as input and check if it is even or odd.
10. Write a function to take a sentence as input and count the number of vowels in it.

Function Returning Value


11. Write a function to take two numbers as input and return their product.
12. Write a function to take a list of numbers as input and return the average.
13. Write a function to take a string as input and return its length.
14. Write a function to take a number as input and return its factorial.
15. Write a function to take a list of strings as input and return the longest string.

You might also like