简体   繁体   中英

What does (1,) mean in Python?

I looked at similar questions but I didn't find this topic anywhere.

I want to know what does the tuple (1,) mean in Python?

From https://wiki.python.org/moin/TupleSyntax

One Element Tuples

One-element tuples look like:

 1,

The essential element here is the trailing comma. As for any expression, parentheses are optional, so you may also write one-element tuples like

(1,)

but it is the comma, not the parentheses, that define the tuple.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM