Python Pioneers: A Beginner's Guide πŸ‡ͺπŸ‡Ή
8.82K subscribers
346 photos
40 videos
24 files
64 links
Welcome to Python Pioneers: Empowering Ethiopian students to embark on their coding journey.

πŸ“’ Channel: @python_pioneers
πŸ‘₯ Group: @python_pioneers_chat
Download Telegram
Functions in programming

αˆ°αˆ‹αˆ α‰€α‰°αˆ°α‰₯πŸ‘‹

α‹›αˆ¬ Functions α‰ Python programming language αˆαŠ• αŠ₯αŠ•α‹°αˆ†αŠ‘ αŠ₯αŠ“ αˆˆαˆαŠ• αŠ₯αŠ•α‹°αˆšαŒ α‰…αˆ™αŠ• αŠ₯αŠ“α‹«αˆˆαŠ•πŸŽ‰

Functions are super cool because they let us reuse blocks of code to make our programs more efficient and organized. πŸ§‘β€πŸ’» You can pass in parameters, return results, and create clean, modular code. Let’s master functions together! πŸš€

Check out more here: Functions in Programming

πŸ‘†αŠ¨αˆ‹α‹­ α‹«αˆˆα‹αŠ• αˆ›αˆ΅αˆαŠ•αŒ αˆͺα‹« α‰ αˆ˜αŠ•αŠ«α‰΅ ሡለ Functions α‹¨α‰ αˆˆαŒ  αˆ˜αˆ¨α‹³α‰΅ α‰΅α‰½αˆ‹αˆ‹α‰½αˆα’

#Functions

@python_pioneers
@python_pioneers
πŸ”₯4
ለ @python_pioneers α‰»αŠαˆ αŠ α‹²αˆ΅ αŠ¨αˆ†αŠ“α‰½αˆ ከሡር α‹«αˆˆα‹αŠ• Button α‰ αˆ˜αŒ«αŠ• αŠ¨α‹šαˆ… α‰ αŠα‰΅ α‹¨α‰°αˆ›αˆ­αŠ“α‰Έα‹αŠ• α‰΅αˆαˆ…αˆ­α‰Άα‰½ αˆ›αŒαŠ˜α‰΅ α‰΅α‰½αˆ‹αˆ‹α‰½αˆα’

#PythonPioneers

@python_pioneers
πŸ‘3
πŸ˜πŸ˜‚πŸ˜πŸ˜‚πŸ˜πŸ˜‚πŸ˜‚πŸ˜‚

Pinterest_Et

#Fun


@python_pioneers
😁11😎1
πŸ‘‰Why Functions?

Stay Tuned...

#Functions

@python_pioneers
πŸ‘1
Function αˆˆαˆαŠ• α‹­αŒ α‰…αˆ˜αŠ“αˆ?

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
Function of Functions

Here are some AI generated pictures about functions.

#Functions

@python_pioneers
πŸ‘4
Calling a Function

# 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
Python Functions

PIC 2⃣

#Functions

@python_pioneers
πŸ‘3πŸ‘2
➑ Lambda Function
πŸ”₯3πŸ‘2
Do the right thing, even when no one is watching.

It's called Integrity.

#Quote

@python_pioneers
πŸ‘7πŸ‘2πŸ•Š2❀1
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
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
❀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
πŸ”₯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 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