ycliper

Популярное

Музыка Кино и Анимация Автомобили Животные Спорт Путешествия Игры Юмор

Интересные видео

2025 Сериалы Трейлеры Новости Как сделать Видеоуроки Diy своими руками

Топ запросов

смотреть а4 schoolboy runaway турецкий сериал смотреть мультфильмы эдисон
Скачать

Python Tutorial: Containers - Lists and Dictionaries

python tutorial

data science

python for r users

programming fundamentals using python

Python containers

Автор: DataCamp

Загружено: 2020-02-25

Просмотров: 2879

Описание: Want to learn more? Take the full course at https://learn.datacamp.com/courses/py... at your own pace. More than a video, you'll learn hands-on coding & quickly apply skills to your daily work.

---

We will now talk about containers: data structures in which you can store multiple data types.

Lists are a very common data structure in Python that can contain multiple data types.

Lists in Python are created with a pair of square brackets, and each element in the list is separated by a comma.

Python is a 0-indexed language, meaning that in Python, the index is counted from 0 instead of 1. This is one of the major sources of confusion when people switch between R and Python.

To extract an element out of a Python list, you use one pair of square brackets. Since Python is a 0-indexed language, to get the first element, you use the index 0.

Another difference in Python is using negative indices to select elements from the end.

So in Python, -1 selects the last element in the list, -2 selects the penultimate element in the list and so on.

Before we extract multiple list elements at once, it's important to show the left inclusive, right exclusive nature of Python.

The best way to see this is by using a fence post analogy. Here the indices are labeled 0 to 5. These labels represent our "fence posts". Between each fence post, you have elements of the list. The elements between the indices 0 and 3 give you the first three elements of the list.

To simultaneously select multiple elements you use the colon notation. The first value represents the beginning index, and the second value represents the last index. You can also have an additional third value to specify a step size. So, if you want to select every other value from the first 5 elements in the list, you would write 0 colon 5 colon 2.

The indices you pass into the colon notation can be optional. Remember the 0-index and the left inclusive right exclusive nature of Python? You are about to see this again. If you leave the first value blank, Python will slice from the beginning all the way to the second specified index. If you leave the second value missing then Python will slice from the first specified index until the end. You can also leave the first two values blank and just specify a step size. This will go through the entire list and return the elements depending on the specified step size.

Lists are great for storing information, but since the elements in the list can actually mean something, a better, and more pythonic way is to associate a label with the elements. You cannot have named lists in Python. Instead, Python "dict"ionaries are one solution to this. Just like an actual dictionary, the data is stored in key-value pairs.

Python dictionaries are created with a pair of curly-brackets. Each key-value pair includes a colon, with the key to the left, and the value to the right of the colon. Multiple key-value pairs are separated by commas. Notice the order of the keys are different from when the dictionary was first defined, and when it was printed. The order of the keys is not guaranteed, so do not rely on the printed order of keys. To extract a "value" from the dictionary, you place the "key" of the dictionary inside the square brackets.

Finally, you can find the length, that is the number of elements, of a list and dictionary by using the built-in len() function.

Time to practice lists and dictionaries.

Не удается загрузить Youtube-плеер. Проверьте блокировку Youtube в вашей сети.
Повторяем попытку...
Python Tutorial: Containers - Lists and Dictionaries

Поделиться в:

Доступные форматы для скачивания:

Скачать видео

  • Информация по загрузке:

Скачать аудио

Похожие видео

Python с нуля | Словари в Python | Методы словарей, перебор словарей в Python

Python с нуля | Словари в Python | Методы словарей, перебор словарей в Python

Python dictionaries are easy 📙

Python dictionaries are easy 📙

Python: Data Structures - Lists, Tuples, Sets & Dictionaries tutorial

Python: Data Structures - Lists, Tuples, Sets & Dictionaries tutorial

Срочное обращение президента / Внезапные протесты против власти

Срочное обращение президента / Внезапные протесты против власти

Python lists, sets, and tuples explained 🍍

Python lists, sets, and tuples explained 🍍

ГАЛЛЯМОВ:

ГАЛЛЯМОВ: "Путин с зеленым лицом орал на своих генералов": что (не)случилось в Кремле, Трамп, КОГДА?

10 минут на улице могут стоить жизни (Жизнь в самом холодном месте на Земле) -71°C

10 минут на улице могут стоить жизни (Жизнь в самом холодном месте на Земле) -71°C

Алгоритмы на Python 3. Лекция №1

Алгоритмы на Python 3. Лекция №1

Смогу ли я превратить MrBeast в МастерШефа?!

Смогу ли я превратить MrBeast в МастерШефа?!

Разрушительный Удар По Промышленному Потенциалу💥🏭 Новоукраина Пала⚔️ Военные Сводки За 29.06.2025 📅

Разрушительный Удар По Промышленному Потенциалу💥🏭 Новоукраина Пала⚔️ Военные Сводки За 29.06.2025 📅

© 2025 ycliper. Все права защищены.



  • Контакты
  • О нас
  • Политика конфиденциальности



Контакты для правообладателей: [email protected]