Friday 30 June 2017

Tuple of Length One in Python

Cited from the book "Data Structure and Algorithms in Python"

To express a tuple of length one as a literal, a comma must be placed after the element, but within the parentheses. For example, (17,) is a one-element tuple. The reason for this requirement is that, without the trailing comma, the expression (17) is viewed as a simple parenthesized numeric expression.

No comments:

Post a Comment