Python Programming - Variables - Discussion

Discussion Forum : Variables - General Questions (Q.No. 21)
21.
Which of the following statements about Python variables is true?
Python is a statically typed language.
A variable must be declared with a type before it can be used.
Python allows multiple assignments in a single line.
A variable's scope is determined by the type of data it holds.
Answer: Option
Explanation:
Python is a dynamically typed language. In Python, a variable's type is inferred from the value it's assigned. A variable's scope is determined by where it's defined in the code.

For example:

a, b, c = 1, 2, 3

This statement assigns the values 1, 2, and 3 to the variables a, b, and c, respectively.

You can also assign the same value to multiple variables in one line:

a = b = c = "Orange"

This statement assigns the value "Orange" to the variables a, b, and c.

If you have a collection of values in a list, tuple, etc. Python allows you to extract the values into variables. This is called unpacking. For example:

fruits = ["apple", "banana", "cherry"]
a, b, c = fruits

This statement extracts the values "apple", "banana", and "cherry" from the list fruits and assigns them to the variables a, b, and c, respectively.

Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.