Ainsteinx Logo
Ainsteinx
👤
Welcome to Ainsteinx
Login

Change Language

Currency

Home
Blog
Services
ທຸກບົດຮຽນ
EP.7 Python ສຳລັບຄົນ 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 ຟັງຊັນ ແລະ OOP

Functions: write once, use many times

Stop copy-pasting code. Make a function.

def ໃຊ້ສ້າງຟັງຊັນ. ຄ່າທີ່ສົ່ງເຂົ້າໄປ ເອີ້ນວ່າ parameter, ແລະ return ສົ່ງຜົນລັບກັບຄືນມາ.

ຕົວຢ່າງນີ້ຄິດລາຄາລວມ ພ້ອມອາກອນ 10%.

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

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

ຜົນລັບ

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