Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
3 views

python functions and conditional statment

The document explains Python functions as reusable code blocks defined with the 'def' keyword that can accept parameters and return outputs. It also covers conditional statements that allow decision-making in programs using keywords like if, elif, and else. Key concepts include types of functions, parameters, return statements, and logical operators.

Uploaded by

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

python functions and conditional statment

The document explains Python functions as reusable code blocks defined with the 'def' keyword that can accept parameters and return outputs. It also covers conditional statements that allow decision-making in programs using keywords like if, elif, and else. Key concepts include types of functions, parameters, return statements, and logical operators.

Uploaded by

ashwini biradar
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 15

NAME :- Jadhav Yash ​

Jagtap Tejas​
ROLL NO.: - 106​
110​
DIV :- A
ACTIVITY:- Python Functions and
Conditional
statment
What are Python Functions?
• Functions are reusable blocks of code
that perform specific tasks.

• - Defined using the 'def' keyword.

• - Can accept inputs (parameters) and


return outputs.
Syntax of a Python Function
• def function_name(parameters):
• '''Docstring'''
• statement(s)

• Example:
• def greet(name):
• return f'Hello, {name}!'
Types of Functions
• 1. Built-in Functions (e.g., print(), len())

• 2. User-defined Functions

• 3. Lambda (Anonymous) Functions


Parameters and Arguments
• - Parameters: Variables in the function
definition.
• - Arguments: Values passed to the function.

• Types:
• 1. Positional Arguments
• 2. Keyword Arguments
• 3. Default Arguments
• 4. Variable-length Arguments (*args,
Return Statement
• The return statement is used to send a result
back to the caller.

• Example:
• def add(a, b):
• return a + b
Lambda Functions
• Lambda functions are anonymous, one-line
functions.

• Syntax:
• lambda arguments: expression

• Example:
• square = lambda x: x ** 2
What are Conditional Statements?
• Conditional statements allow decision-making
in a program.

• - Use keywords like if, elif, and else.

• - Help control the flow of the program.


Syntax of if Statement
• if condition:
• statement(s)

• Example:
• if x > 0:
• print('Positive number')
if-else Statement
• if condition:
• statement(s)
• else:
• statement(s)

• Example:
• if x % 2 == 0:
• print('Even')
• else:
if-elif-else Statement
• if condition1:
• statement(s)
• elif condition2:
• statement(s)
• else:
• statement(s)

• Example:
• if marks >= 90:
Nested if Statements
• An if statement inside another if statement.

• Example:
• if age > 18:
• if has_license:
• print('You can drive')
• else:
• print('Get a license first')
Logical Operators in Conditions
• Logical operators combine multiple
conditions:
• - and: Both conditions must be True.
• - or: At least one condition must be True.
• - not: Negates a condition.

• Example:
• if age > 18 and has_license:
• print('You can drive')
Ternary Conditional Statement
• A compact way to write if-else statements.

• Syntax:
• value_if_true if condition else value_if_false

• Example:
• result = 'Pass' if marks >= 50 else 'Fail'
Summary
• - Functions simplify code reuse and
modularity.
• - Conditional statements control the flow of
execution.
• - Practice writing functions and using if-else
logic in real problems.

You might also like