Function ααα αα α
ααα?
1. Code Reusability:
Functions α αα΅α α¨ααααα code α α°α°ααα α₯αα΅αα ααα αα¨α³ααα’ α αα΄ Function define α«α¨αα α£ α₯α αα call α₯α«α¨ααα α αα¨ααα α¦α³ αα αα α₯αα½αααα’ α΅ααα α¨ααα code α α°α°ααα ααα α αα α α α₯ααα’
2. Modularity:
αα α¨ Function α₯α α α°αα α αα΅α complex problem αα₯α α¨α°αα«α© parts α¨ααα α₯α«αα³αα±α part α°αα function α αααα΅ α ααα ααα΅α α₯αα΅ααα αα¨α³ααα’
3. Readability:
αααα α¨ Function α₯α α α°αα α¨αααα code α ααα α₯αα²αα α₯ α«α¨αααα£ This helps other developers (and you, in the future) understand the code easily.
4. Avoiding Redundancy:
α αα΅ α¨ code block α₯α αα αα αα α¨ααααα£ α αα΅ αα function define α ααα α ααα α₯α call αα΅α¨α α₯αα½αααα£ αα α°αα α α°α°ααα α₯α¨ααα α΅α α°α΅ α₯αα³αα°α« αα¨α³ααα’
β’β’β’
#Functions
@python_pioneers
@python_pioneers
1. Code Reusability:
Functions α αα΅α α¨ααααα code α α°α°ααα α₯αα΅αα ααα αα¨α³ααα’ α αα΄ Function define α«α¨αα α£ α₯α αα call α₯α«α¨ααα α αα¨ααα α¦α³ αα αα α₯αα½αααα’ α΅ααα α¨ααα code α α°α°ααα ααα α αα α α α₯ααα’
def greet():
print("Hello, world!")
greet() # Reusing the same function
greet()
2. Modularity:
αα α¨ Function α₯α α α°αα α αα΅α complex problem αα₯α α¨α°αα«α© parts α¨ααα α₯α«αα³αα±α part α°αα function α αααα΅ α ααα ααα΅α α₯αα΅ααα αα¨α³ααα’
def calculate_area(radius):
return 3.14 * radius * radius
3. Readability:
αααα α¨ Function α₯α α α°αα α¨αααα code α ααα α₯αα²αα α₯ α«α¨αααα£ This helps other developers (and you, in the future) understand the code easily.
def calculate_average(marks):
return sum(marks) / len(marks)
4. Avoiding Redundancy:
α αα΅ α¨ code block α₯α αα αα αα α¨ααααα£ α αα΅ αα function define α ααα α ααα α₯α call αα΅α¨α α₯αα½αααα£ αα α°αα α α°α°ααα α₯α¨ααα α΅α α°α΅ α₯αα³αα°α« αα¨α³ααα’
def convert_to_fahrenheit(celsius):
return (celsius * 9/5) + 32
β’β’β’
#Functions
@python_pioneers
@python_pioneers
π2
π4
Calling a Function
Calling a function ααα΅ literally α¨α°α¨ααα Function αα₯α«α΅ ααα£ αα α ααα΅ α αα΅ define α¨α°α°α¨α function executed α₯αα²αα αα₯α«α΅ α₯αα°ααα΅ ααα’
When you call a function, the program jumps to the function's code, runs it, and then continues from where the function was called.
αα₯α«αͺα«
β’
Return α¨αα£αα statement α₯α α αα€α±α αα° callerα‘ αααα΅α functionα‘α exit αα΅α¨α ααα’
Return statement executed α¨αα functionα‘α α«αααα functionα‘ call α α°α°α¨αα α΅ specified α¨αααα αα€α΅ αα°α£αα’
Return statement α₯αα΄α΅ αα°α«α?
- Syntax:
-
ααααα ααα α¨ return statement αα₯α α¨αα functionα‘ by default 'None' return α«α¨ααα’
αααα α¨ return statement α₯α α α αα΅ function define α ααα α¨αα α¨functionα‘ α¨ααααα αα€α΅ α¨functionα‘ ααͺ α αα variable αα΅α₯ store α ααα α₯αα΅αα ααα αα¨α³ααα’
αα³α
α αα αα³α `return number ** 2' α¨ 'number'α squared value 'square()' α¨α°α£αα function call αα°α°α°α¨αα α΅ ααα«αα£ α¨α return α¨α°α°α¨αα squared value α¨functionα‘ ααͺ result α¨α°α£α variable αα΅α₯ store αα°α¨ααα£ then print αα°α¨ααα’
#Return
#CallingaFunction
#Function
@python_pioneers
@python_pioneers
@python_pioneers
# Define a function that adds two numbers
def add_numbers(num1, num2):
result = num1 + num2
return result
# Calling the function
sum_result = add_numbers(5, 3)
print("The sum is:", sum_result) # Outputs: The sum is: 8
Calling a function ααα΅ literally α¨α°α¨ααα Function αα₯α«α΅ ααα£ αα α ααα΅ α αα΅ define α¨α°α°α¨α function executed α₯αα²αα αα₯α«α΅ α₯αα°ααα΅ ααα’
When you call a function, the program jumps to the function's code, runs it, and then continues from where the function was called.
αα₯α«αͺα«
β’
add_numbers: αα function ααα΅ parameter ααα΅α³αα£ α¨α αα°αα«αΈαα αα€α±α return α«α¨ααα’Return α¨αα£αα statement α₯α α αα€α±α αα° callerα‘ αααα΅α functionα‘α exit αα΅α¨α ααα’
Return statement executed α¨αα functionα‘α α«αααα functionα‘ call α α°α°α¨αα α΅ specified α¨αααα αα€α΅ αα°α£αα’
Return statement α₯αα΄α΅ αα°α«α?
- Syntax:
return <expression>-
<expression> ααααα α ααα΅ value ααα αα½αα variable, even a result of a calculation.ααααα ααα α¨ return statement αα₯α α¨αα functionα‘ by default 'None' return α«α¨ααα’
αααα α¨ return statement α₯α α α αα΅ function define α ααα α¨αα α¨functionα‘ α¨ααααα αα€α΅ α¨functionα‘ ααͺ α αα variable αα΅α₯ store α ααα α₯αα΅αα ααα αα¨α³ααα’
αα³α
def square(number):
return number ** 2
# Calling the function and storing the result
result = square(4)
print("The square is:", result) # Outputs: The square is: 16
α αα αα³α `return number ** 2' α¨ 'number'α squared value 'square()' α¨α°α£αα function call αα°α°α°α¨αα α΅ ααα«αα£ α¨α return α¨α°α°α¨αα squared value α¨functionα‘ ααͺ result α¨α°α£α variable αα΅α₯ store αα°α¨ααα£ then print αα°α¨ααα’
#Return
#CallingaFunction
#Function
@python_pioneers
@python_pioneers
@python_pioneers
π3
Are you a current 2017 freshman university student or have you been accepted by Ethiopian universities?
Anonymous Poll
64%
Yes
36%
No
π1
Good evening!
Current 2017 freshman university students: If you are interested in transferring to Asosa University, please DM me using this telegram account π @MntsntZP
@python_pioneers
Current 2017 freshman university students: If you are interested in transferring to Asosa University, please DM me using this telegram account π @MntsntZP
@python_pioneers
Python Pioneers: A Beginner's Guide πͺπΉ pinned Β«Good evening! Current 2017 freshman university students: If you are interested in transferring to Asosa University, please DM me using this telegram account π @MntsntZP @python_pioneersΒ»
We've reached 450 subscribers now, we're 4.5/10 of our goal which is huge for a channel with no videos. So thank you so much. Keep on subscribing and sharing.
β’ youtube.com/@Dagmawi_Babi
Thank You So Much! β€οΈ
@Dagmawi_Babi
β’ youtube.com/@Dagmawi_Babi
Thank You So Much! β€οΈ
@Dagmawi_Babi
β€5
Hey everyone! Sorry it's been a while since our last meeting. Today, we're diving into an exciting lesson about lambda functions in Python.
Looking forward to seeing you all!
#LambdaFunctions
@python_pioneers
Looking forward to seeing you all!
#LambdaFunctions
@python_pioneers
π₯5π1
Lambda Functions in Python
Lambda functions α αα α΅ααΈα anonymous functions α Python Programming language αα΅α₯ at a runtime α αα α₯α unnamed functions α₯αα΅ααα₯α α«ααααα’ αα α¦α³ αα αα α«ααααααα function α α αα΅ α¦α³ α₯α» α₯αα΅ααα₯α αα¨α±ααα’
What is a Lambda Function?
Lambda function α¨αααααα α«α α argument ααα΅α³α ααα αα α αα΅ expression α₯α» αα α¨ααα ααα’ Expression α‘ evaluated α¨αα α αα value return αα°α¨ααα’
The syntax for a lambda function is:
α¨lambda functions ααα α£α αͺα«α΅
1. Anonymous: Lambda functions α΅α α¨ααΈααα£ that means they're anonymous.
2. Single Expression: α αα΅ expression α₯α» αα α¨αααα΅α£ αα α°αα α¨regular functions less powerful α«α°αααΈααα’
3. Can Take Multiple Arguments: α₯α argument α¨ααα α α α α α ααΈαα’
Lambda function α¨regular function α syntax α₯αα΄α΅ α₯αα°ααα α¨α΅α α£αα αα³α αα¨α³α΅ αα»ααα’
αα³α : Basic Lambda Function
to be contd...
#LambdaFunctions
#Functions
#Python
@python_pioneers
Lambda functions α αα α΅ααΈα anonymous functions α Python Programming language αα΅α₯ at a runtime α αα α₯α unnamed functions α₯αα΅ααα₯α α«ααααα’ αα α¦α³ αα αα α«ααααααα function α α αα΅ α¦α³ α₯α» α₯αα΅ααα₯α αα¨α±ααα’
What is a Lambda Function?
Lambda function α¨αααααα α«α α argument ααα΅α³α ααα αα α αα΅ expression α₯α» αα α¨ααα ααα’ Expression α‘ evaluated α¨αα α αα value return αα°α¨ααα’
The syntax for a lambda function is:
lambda arguments: expression
α¨lambda functions ααα α£α αͺα«α΅
1. Anonymous: Lambda functions α΅α α¨ααΈααα£ that means they're anonymous.
2. Single Expression: α αα΅ expression α₯α» αα α¨αααα΅α£ αα α°αα α¨regular functions less powerful α«α°αααΈααα’
3. Can Take Multiple Arguments: α₯α argument α¨ααα α α α α α ααΈαα’
Lambda function α¨regular function α syntax α₯αα΄α΅ α₯αα°ααα α¨α΅α α£αα αα³α αα¨α³α΅ αα»ααα’
αα³α : Basic Lambda Function
# Regular function
def add(x, y):
return x + y
# Lambda function
add_lambda = lambda x, y: x + y
print(add(2, 3)) # Output: 5
print(add_lambda(2, 3)) # Output: 5
to be contd...
#LambdaFunctions
#Functions
#Python
@python_pioneers
Forwarded from AAU Software Engineering community (Aquaphile π¨ββοΈ)
Media is too big
VIEW IN TELEGRAM
Hello, ASEC π¨βπ»π©βπ» friends and family!
This is our educational channel by ASEC! Our goal and dedication is to create best learning and networking environment for tech enthusiasts and programmers of all backgrounds. Although we are a new channel with a smaller subscriber base, we previously had a channel with 21.3k subscribers that was lost for no reason. Don't judge us by our current subscribers count instead we invite you to join us to explore and enjoy learning plus feel free to invite your besties to this exciting experience.
In addition to our educational contents, we also offer Smart ICT Solutions for organizations and individuals.With extensive experience in this field, we are committed to provide valuable services to those in need.
This is our educational channel by ASEC! Our goal and dedication is to create best learning and networking environment for tech enthusiasts and programmers of all backgrounds. Although we are a new channel with a smaller subscriber base, we previously had a channel with 21.3k subscribers that was lost for no reason. Don't judge us by our current subscribers count instead we invite you to join us to explore and enjoy learning plus feel free to invite your besties to this exciting experience.
In addition to our educational contents, we also offer Smart ICT Solutions for organizations and individuals.With extensive experience in this field, we are committed to provide valuable services to those in need.
π3β€1