3.4 More about variables

mohit355

Mohit Raj

Posted on December 7, 2019

3.4 More about variables

Declaring more than one variable in single line:

=>> yes we can declaring more than one variable in a single line and assign it different value.

for example

x,y=1,2
print(x)
print(y)
Enter fullscreen mode Exit fullscreen mode

output is

1
2
Enter fullscreen mode Exit fullscreen mode

==>> we can assign any variable with and data type of values in single line
For example

a,b,c=1,'mohit','123as'
print(a,type(a))
print(b,type(b))
print(c,type(c))
Enter fullscreen mode Exit fullscreen mode

output is

1 <class int>
mohit <class str>
123as <class str>
Enter fullscreen mode Exit fullscreen mode

=>> We can also assign a single value to more than one variable in single line.
For example

x=y=z=12
print(x)
print(y)
print(z)
print(x,y,z)
print(x+y+z)
Enter fullscreen mode Exit fullscreen mode

Output is

12
12
12
12 12 12
36
Enter fullscreen mode Exit fullscreen mode

Thank you and if you have any problem regarding this please let me know in the comment box

💖 💪 🙅 🚩
mohit355
Mohit Raj

Posted on December 7, 2019

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related