Bug of the week #6
pikoTutorial

pikoTutorial @pikotutorial

About: Inspired by the SI unit prefix “pico” (10^-12), this place aims to deliver short and targeted tutorials which can speed up work of every software engineer.

Joined:
Dec 14, 2024

Bug of the week #6

Publish Date: Apr 1
0 0

Welcome to the next pikoTutorial !

The error we're handling today is a Python runtime error:

ValueError: too many values to unpack
Enter fullscreen mode Exit fullscreen mode

What does it mean?

The "too many values to unpack" error typically occurs when there is a mismatch between the number of variables or elements being unpacked and the number of values being assigned. This situation commonly arises in unpacking sequences like tuples or lists during assignment operations.

How to fix it?

Let's look at the following code:

a, b = [1, 2, 3]
Enter fullscreen mode Exit fullscreen mode

In this example a list from which we're taking values has 3 elements, but we've provided only to variables to store them (a and b), so the value 3 has no place to go. To fix this, either add an additional variable or reduce the number of elements in the list.

a, b, c = [1, 2, 3]
Enter fullscreen mode Exit fullscreen mode
a, b = [1, 2]
Enter fullscreen mode Exit fullscreen mode

Comments 0 total

    Add comment