Hàm trong Python

Khai bao ham theo cu phap:

def functioname(param,param2,..):
statements(s)

Hàm nếu không trả dữ liệu thì mặc định sẽ trả về giá trị
None

def sum(a,b):
return (a+b)
print(sum(8, 2))
(trả về giá trị là 10)
def plus(c,d=10):
return(c+d)
print(plus(2))
(trả về giá trị là 12)

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Design a site like this with WordPress.com
Get started