DEV Community

Mohit Raj
Mohit Raj

Posted on

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

Top comments (0)