Robotics & Artificial Intelligence
How will you assign multiple objects to multiple variables? Explain with the help of an example.
Python Funda
3 Likes
Answer
Python language facilitates assigning multiple objects to multiple variables in a single statement. The values may be of mixed data types like integer, floating point numbers, strings, etc. This is done by separating the variables and their corresponding values with commas.
Syntax: var1, var2, var3 = value1, value2, value3
Example:
m, n, wd = 146, 2020, "Computer"
print(m)
print(n)
print(wd)
Output:
146
2020
Computer
Here, two integers with values 146 and 2020 are assigned to the variables m and n respectively, and one string with the value "Computer" is assigned to the variable wd, all in a single statement.
Answered By
3 Likes
Related Questions
Explain the following data types:
(a) String
(b) List
(c) Tuple
(d) Dictionary
What is meant by Python Sets? Explain with the help of an example.
What are the rules to assign a variable in a Python code?
Explain each of the following with an example:
(i) Implicit type conversion
(ii) Explicit type conversion