RUVIDEO
Поделитесь видео 🙏

PYTHON | Part - 5 | Tuples in Python

📁 Обучение 👁️ 16 📅 02.12.2023

Hello Everyone,

A tuple in Python is similar to a list. The difference between the two is that we cannot change the elements of a tuple once it is assigned whereas we can change the elements of a list.

A tuple is created by placing all the items (elements) inside parentheses (), separated by commas. The parentheses are optional, however, it is a good practice to use them.

A tuple can have any number of items and they may be of different types (integer, float, list, string, etc.)

A tuple can also be created without using parentheses. This is known as tuple packing.

Access Tuple Elements

There are various ways in which we can access the elements of a tuple.

1. Indexing
We can use the index operator [] to access an item in a tuple, where the index starts from 0.

So, a tuple having 6 elements will have indices from 0 to 5. Trying to access an index outside of the tuple index range(6,7,... in this example) will raise an IndexError.

The index must be an integer, so we cannot use float or other types. This will result in TypeError.

2. Negative Indexing
Python allows negative indexing for its sequences.

The index of -1 refers to the last item, -2 to the second last item and so on.

3. Slicing
We can access a range of items in a tuple by using the slicing operator colon :

Unlike lists, tuples are immutable.

This means that elements of a tuple cannot be changed once they have been assigned. But, if the element is itself a mutable data type like list, its nested items can be changed.
[11:27 AM, 6/26/2020] Dhulo: for list
[11:28 AM, 6/26/2020] Shubh Jani: ??
[11:29 AM, 6/26/2020] Dhulo: Python offers a range of compound data types often referred to as sequences. List is one of the most frequently used and very versatile data types used in Python.

In Python programming, a list is created by placing all the items (elements) inside square brackets [], separated by commas.

It can have any number of items and they may be of different types (integer, float, string, etc.).

A list can also have another list as an item. This is called a nested list.

How to access elements from a list?
There are various ways in which we can access the elements of a list.

List Index
We can use the index operator [] to access an item in a list. In Python, indices start at 0. So, a list having 5 elements will have an index from 0 to 4.

Trying to access indexes other than these will raise an IndexError. The index must be an integer. We can't use float or other types, this will result in TypeError.

Nested lists are accessed using nested indexing.

Negative indexing
Python allows negative indexing for its sequences. The index of -1 refers to the last item, -2 to the second last item, and so on.

We can access a range of items in a list by using the slicing operator :(colon).

So, Stay Tuned for more.

Check us out for more updates:
Instagram - https://bit.ly/2WJioSw
Facebook - https://bit.ly/2VckgCq

Join our Whatsapp Group for regular updates and doubt solving.
Whatsapp Group - https://bit.ly/2xDhcpP

If you are having any suggestions for us to make your learning a better experience, write to us in the COMMENT section.

Don't forget to LIKE, SHARE & SUBSCRIBE
Thank You for watching!!

#PYTHON #webdevelopment #TuplesinPython #Tuples

Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «PYTHON | Part - 5 | Tuples in Python», вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.

Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.

Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!

Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.