The right way to declare multiple variables in Python

Sharing buttons:

hello clever polymers and welcome to

soft hands in this view I want to share

with you how to declare multiple

variables in Python and how to do the

right way and what should be avoid I

will share some common errors for

beginners and finally I will demonstrate

some techniques why we have problems

with multiple variable declaration in

Python before to start I will share

another picture from commit strip and

guys having problem with naming their

variable they try data data DB list

completed ArrayList data completed after

hours of fighting it seems that final

date all busted and my question for you

is do you have problems naming your

variables do you have problems with

naming projects and stuff like this can

you share some funny moments or some

good examples and bad examples and why

is not good I will expect your comments

in the comment section below so let's go

back on our topic first we will see

simple declaration of multiple variables

when we have different values and when

we have a single value and let's see our

example here we can see how to declare

multiple variables when we have

different values for example here we

have river three variables Hicks Egret

and set or XY and Z depending on your

language and we assign value on to all

them below you can see one two and three

again assigning to these variables and

as you can know already Putin is three

and you can omit the type so the type is

going to be in for automatically

peyten is strictly object-oriented which

means that everything is object in

Python so this is great as an object the

same is for this one and we have

assigned an object ID with each of these

variables and we'll see later why this

is important and how to use it here we

are assigning one string and a list and

here we have two boolean values and what

is going to happen if I add one more

bell here maybe you think that we are

going to initialize Higgs we true agree

with true and we'll just skip this but

you're wrong in this case because we

have arrow it seems that there are too

many values to unpack and we expect only

two and what is going to happen if we

have the reverse case we have only one

value again we have eroded this time is

saying that the type of this value here

it's not iterable and cannot be iterated

over it in order to assign values to

these two variables okay so these are

the two errors that we have how we can

assign one and the same value for our

variables we can do it in this way or we

can add equal signs here and this is

fine and it's working and if we want to

see what values do have about sorry

about x and y we can see that here we

have true which is okay which is

perfectly fine for us but let's see what

objects do we have

because this could be a problem

sorry I didn't put Yeti here oh okay so

it seems that we have one in the same

object ID for both of them and is this a

real problem let's check for example

let's do X minus 1 and let us print


I want to print the values not the ID

okay so let's print the value of course

this doesn't make sense so I will make

it like this and as you can see right

now we have three but what is going to

happen if I do this operation as you can

see we have again free if we print X

right now you can see that we have minus

one so we don't have any problem right

now here but let's check what is going

to happen if we have another situation

and I wanted to see where this situation

yeah it's this one so let's see what is

going to happen if we initialize declare

any initialize 3 variables to a list and

then append a variety of the lists and

then again do the same thing for another

list maybe you expect to have a egret to

be equal to X and 5 and X or fixed be

equal to s and 5 but let's check what's

going to happen so it seems that we have

free eco lists which means that our

variables are pointing to one and the

same object in memory which means that

every time when we are modifying one of

the lists they are going to have the

same modification which is a real

problem and the best way to check this

is by using code like this getting the

ideas of the all the variables and

checking what is happening and as you

can see on the first iteration we have

one in the same object assigned to the

free variables and on the next one we

are assigning a different object so if

we print the last values after this

modification will have different value

for y but these are some of the problems

that you need to kick to have in mind

and take care when you're dealing with

multiple assignments and multiple

declaration of Python variables so let's

go on how to declare them using topple

lists and ranges you can assign non

value to these free variables by using

this syntax double moon Asterix and free

you can do the same also with true or

any boolean value you can use the range

for example 0 to 3 to assign values 0 1

and 2 to these variables and finally you

can use a list like this

and if we run the code everything is

going to be ok but if you add one more

element to this list you have an arrow

the same as we saw it already the same

it is for the rest of the examples

so you need to be really careful when

you're dealing with these situations and

finally I want to share one another

error with you which was a clear one an

easy one but maybe it's difficult for

beginners we not have enough valve to

unpack so as you can see here we expect

three but we got zero and the way to

solve this is by adding elements here so

the other error was in table jek was not

iterable when we have less values

comparing to the variables and on the

other hand if we have more value than

variable we have too many values to

unpack so these are the three common

errors for multiple declaration and if

you have any questions as always please

do share them in the comment section

below you can see the one of the latest

videos from me on the screen you can see

the subscribe button so if you like the

videos please do subscribe thank you for

watching and see you next time