loading...

3.4 More about variables

github logo ・1 min read

Python for Beginners (18 Part Series)

1) [0.1] Python for beginners Introduction-1 2) [0.2] Python for beginners introduction-2 3 ... 16 3) [0.3] Python for beginners Introduction-3 4) 1.2 Download and install Python 3.x 5) 2.1 Python basics 6) 2.2 Python as a calculator 7) 2.3 Variables in Python 8) 3.1 String Concatenation 9) 3.2 How to take User input in python 10) Sorry for delay in the tutorial 11) 3.3 Type casting in Python 12) 3.4 More about variables 13) 3.5 split() method in Python 14) 3.6 Exercise for you 15) 4.1 String formatting in python Part-1 16) 4.1 String formatting in python Part-2 17) 4.2 index() and find() method - Python 18) 4.3 String slicing

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)

output is

1
2

==>> 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))

output is

1 <class int>
mohit <class str>
123as <class str>

=>> 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)

Output is

12
12
12
12 12 12
36

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

twitter logo DISCUSS
Classic DEV Post from Aug 13 '19

How open-source will Tumblr become?

Mohit Raj profile image
Python lover

What are you waiting for? 100,000 other devs have already joined. join dev.to