Functions
A function is a block of code which only runs when it is called. You can pass data, known as parameters, into a functionTypes of Functions in Python Built-in Functions: These are functions that are built into the Python language, such as print() and len(). User-Defined Functions: These are functions that are defined by the user in their code. Anonymous Functions: These are functions that are defined without a name, using the lambda keyword. Practical Example of Functions in Python Here's an example of a custom function that takes a string as an argument and returns the string in uppercase: def to_uppercase(string): return () Defining and Using Custom Functions Custom functions can be defined by using the def keyword, followed by the function name and parameters in parentheses. The code inside the function is indented and is called the function body. Custom functions can be used by calling them by their name and passing any necessary arguments in parentheses.
Written for
- Institution
- Bharathiar University
- Course
- Basic
Document information
- Uploaded on
- October 24, 2024
- Number of pages
- Unknown
- Written in
- 2024/2025
- Type
- ESSAY
- Professor(s)
- Unknown
- Grade
- B
Subjects
-
else
-
if