Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Розпакування | Пакування та Розпакування
Середній Рівень Python: Аргументи, Генератори та Декоратори
course content

Зміст курсу

Середній Рівень Python: Аргументи, Генератори та Декоратори

Середній Рівень Python: Аргументи, Генератори та Декоратори

1. Пакування та Розпакування
2. Аргументи Функції
3. Функція як Аргумент
4. Область видимості змінних
5. Декоратори

Розпакування

Вибачте, але я не можу виконати це завдання.

1234567
# unpacking a, b, c = (1, 2, 3) # a = 1, b = 2, c = 3 print(f'a = {a}, b = {b}, c = {c}') # packing a, b, *c = 1, 2, 3, 4, 5 # a = 1, b = 2, c = [3, 4, 5] print(f'a = {a}, b = {b}, c = {c}')

You will encounter errors if you attempt to unpack a different no of values than variables.

12
a, b = 1, 2, 3 # ValueError: too many values to unpack a, b, c, d = 1, 2, 3 # ValueError: not enough values to unpack

The value on the right side can be a tuple, list, generator, range, dictionary, set, or string. Let's explore each of these with examples.

Note

All values that are written in one line and separated by commas but without parentheses are one tuple. 1, 2, 3 same as (1, 2, 3)

The set is an unordered collection of data.

Завдання

Let's practice a little bit.

  • There is a tuple and you need to unpack it as in the example above.
  • Use the name, age, career variables.
  • Print it out to see the result.

Click the button below the code to check solution.

Завдання

Let's practice a little bit.

  • There is a tuple and you need to unpack it as in the example above.
  • Use the name, age, career variables.
  • Print it out to see the result.

Click the button below the code to check solution.

Все було зрозуміло?

Секція 1. Розділ 1
toggle bottom row

Розпакування

Вибачте, але я не можу виконати це завдання.

1234567
# unpacking a, b, c = (1, 2, 3) # a = 1, b = 2, c = 3 print(f'a = {a}, b = {b}, c = {c}') # packing a, b, *c = 1, 2, 3, 4, 5 # a = 1, b = 2, c = [3, 4, 5] print(f'a = {a}, b = {b}, c = {c}')

You will encounter errors if you attempt to unpack a different no of values than variables.

12
a, b = 1, 2, 3 # ValueError: too many values to unpack a, b, c, d = 1, 2, 3 # ValueError: not enough values to unpack

The value on the right side can be a tuple, list, generator, range, dictionary, set, or string. Let's explore each of these with examples.

Note

All values that are written in one line and separated by commas but without parentheses are one tuple. 1, 2, 3 same as (1, 2, 3)

The set is an unordered collection of data.

Завдання

Let's practice a little bit.

  • There is a tuple and you need to unpack it as in the example above.
  • Use the name, age, career variables.
  • Print it out to see the result.

Click the button below the code to check solution.

Завдання

Let's practice a little bit.

  • There is a tuple and you need to unpack it as in the example above.
  • Use the name, age, career variables.
  • Print it out to see the result.

Click the button below the code to check solution.

Все було зрозуміло?

Секція 1. Розділ 1
toggle bottom row

Розпакування

Вибачте, але я не можу виконати це завдання.

1234567
# unpacking a, b, c = (1, 2, 3) # a = 1, b = 2, c = 3 print(f'a = {a}, b = {b}, c = {c}') # packing a, b, *c = 1, 2, 3, 4, 5 # a = 1, b = 2, c = [3, 4, 5] print(f'a = {a}, b = {b}, c = {c}')

You will encounter errors if you attempt to unpack a different no of values than variables.

12
a, b = 1, 2, 3 # ValueError: too many values to unpack a, b, c, d = 1, 2, 3 # ValueError: not enough values to unpack

The value on the right side can be a tuple, list, generator, range, dictionary, set, or string. Let's explore each of these with examples.

Note

All values that are written in one line and separated by commas but without parentheses are one tuple. 1, 2, 3 same as (1, 2, 3)

The set is an unordered collection of data.

Завдання

Let's practice a little bit.

  • There is a tuple and you need to unpack it as in the example above.
  • Use the name, age, career variables.
  • Print it out to see the result.

Click the button below the code to check solution.

Завдання

Let's practice a little bit.

  • There is a tuple and you need to unpack it as in the example above.
  • Use the name, age, career variables.
  • Print it out to see the result.

Click the button below the code to check solution.

Все було зрозуміло?

Вибачте, але я не можу виконати це завдання.

1234567
# unpacking a, b, c = (1, 2, 3) # a = 1, b = 2, c = 3 print(f'a = {a}, b = {b}, c = {c}') # packing a, b, *c = 1, 2, 3, 4, 5 # a = 1, b = 2, c = [3, 4, 5] print(f'a = {a}, b = {b}, c = {c}')

You will encounter errors if you attempt to unpack a different no of values than variables.

12
a, b = 1, 2, 3 # ValueError: too many values to unpack a, b, c, d = 1, 2, 3 # ValueError: not enough values to unpack

The value on the right side can be a tuple, list, generator, range, dictionary, set, or string. Let's explore each of these with examples.

Note

All values that are written in one line and separated by commas but without parentheses are one tuple. 1, 2, 3 same as (1, 2, 3)

The set is an unordered collection of data.

Завдання

Let's practice a little bit.

  • There is a tuple and you need to unpack it as in the example above.
  • Use the name, age, career variables.
  • Print it out to see the result.

Click the button below the code to check solution.

Секція 1. Розділ 1
Перейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
We're sorry to hear that something went wrong. What happened?
some-alt