How to Create Tuples With 1 or 0 Items in Python | Quick Python

Опубликовано: 25 Май 2021
на канале: choobtorials
336
5

In this Python video tutorial, we'll learn how to create tuples that have either 0 items or just 1 item.

==========

In Python, empty tuples are constructed using an empty pair of parentheses, like so. If we check this example, we see that it does, in fact, evaluate into a tuple. And if we check the length, we see that it returns 0.

But to create a tuple with 1 item, putting a single value in parentheses will not work. As you can see here, a single value in parentheses simply evaluates into the same value without the parentheses. To construct a tuple with one item, the value must be followed by a trailing comma, and the parentheses become optional. You need them for empty tuples, but they’re not always necessary for tuples that have 1 or more items. So now, if we check this, we see that we have a tuple that contains just 1 item.


==========

Twitter:
#Python #Shorts


На этой странице сайта вы можете посмотреть видео онлайн How to Create Tuples With 1 or 0 Items in Python | Quick Python длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь choobtorials 25 Май 2021, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 336 раз и оно понравилось 5 зрителям. Приятного просмотра!