2

I am learning Python 3. I came across below code.

class Calculator:
    def addition(x,y,):
        print(x+y)
    def multiplication(x,y):
        print(x*y)

print(Calculator.addition(5,5))

And it prints 10

Why it doesn't give syntax error for the extra comma in addition(x,y,) ? method. Why it worked ?

thatisvivek
  • 875
  • 1
  • 12
  • 30
  • Python allows it, the comma has no meaning, so why would that need to be a syntax error? – Martijn Pieters Aug 27 '14 at 17:12
  • It works because a trailing comma is permitted by [the language specification](https://docs.python.org/2/reference/compound_stmts.html#function-definitions). Why the specification permits it, is a matter of speculation. Only the BDFL can know for sure ;-) – Kevin Aug 27 '14 at 17:14
  • 2
    It looks inconsistent in the first exposure. By the way why meaningless commas are allowed ? – thatisvivek Aug 27 '14 at 17:17

0 Answers0