Ainsteinx Logo
Ainsteinx
👤
Welcome to Ainsteinx
Login

Change Language

Currency

Home
Blog
Services
All lessons
EP.7 Python for Laos

Functions: write once, use many times

def total(price, tax=0.10):
    return price + price * tax

print(total(50000))
print(total(20000, 0))
Video coming soon
EP.7 Functions & OOP

Functions: write once, use many times

Stop copy-pasting code. Make a function.

def creates a function. The values you pass in are called parameters, and return sends the result back.

This example works out a total price including 10% tax.

ep07-functions.py
def total(price, tax=0.10):
    return price + price * tax

print(total(50000))
print(total(20000, 0))

Output

55000.0
20000
  • #PythonສຳລັບຄົນLaos
  • #Python
  • #ຮຽນໂປຣແກຣມ
  • #ບອກຕໍ່ຄວາມຮູ້
  • #shorts

Watch and share on