You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+32
Original file line number
Diff line number
Diff line change
@@ -1481,6 +1481,38 @@ tuple()
1481
1481
1482
1482
---
1483
1483
1484
+
### The surprising comma
1485
+
1486
+
Suggested by @MostAwesomeDude in [this](https://github.com/satwikkansal/wtfPython/issues/1) issue.
1487
+
1488
+
**Output:**
1489
+
```py
1490
+
>>>def f(x, y,):
1491
+
...print(x, y)
1492
+
...
1493
+
>>>def g(x=4, y=5,):
1494
+
...print(x, y)
1495
+
...
1496
+
>>>def h(x, **kwargs,):
1497
+
File "<stdin>", line 1
1498
+
def h(x, **kwargs,):
1499
+
^
1500
+
SyntaxError: invalid syntax
1501
+
>>>def h(*args,):
1502
+
File "<stdin>", line 1
1503
+
def h(*args,):
1504
+
^
1505
+
SyntaxError: invalid syntax
1506
+
```
1507
+
1508
+
#### 💡 Explanation:
1509
+
1510
+
- Trailing comma isnot always legal in formal parameters list of a Python function.
1511
+
- In Python, the argument listis defined partially with leading commas and partially with trailing commas. This conflict causes situations where a comma is trapped in the middle, and no rule accepts it.
1512
+
-**Note:** The trailing comma problem is [fixed in Python 3.6](https://bugs.python.org/issue9232). The remarks in [this](https://bugs.python.org/issue9232#msg248399) post discuss in brief different usages of trailing commas in Python.
1513
+
1514
+
---
1515
+
1484
1516
### For what?
1485
1517
1486
1518
Suggested by @MittalAshok in [this](https://github.com/satwikkansal/wtfpython/issues/23) issue.
0 commit comments