Python อนุญาตให้อาร์กิวเมนต์ของฟังก์ชันมีค่าเริ่มต้น (default values) หากเรียกฟังก์ชันโดยไม่ส่งอาร์กิวเมนต์ตัวนั้น จะใช้ค่าเริ่มต้นโดยอัตโนมัติ นอกจากนี้ยังสามารถระบุอาร์กิวเมนต์ด้วยชื่อ (named arguments) ได้ในลำดับใดก็ตาม
ตัวอย่าง
def greet(name, msg='Good Morning', msg2='Come on in'):
return (msg, f'{name}, {msg} {msg2}')
print(greet('Archie')) # ใช้ค่าเริ่มต้นทั้งสอง
print(greet('Richie', 'How do you do?')) # msg2 ยังคงเป็นค่าเริ่มต้น
ผลลัพธ์
('Good Morning', 'Archie, Good Morning Come on in')
('How do you do?', 'Richie, How do you do? Come on in')
ในตัวอย่าง name เป็น required argument (ต้องส่งเสมอ) ส่วน msg และ msg2 เป็น optional arguments ที่มีค่าเริ่มต้น