Question Detail

COS 102 lecture 4 Objective Question

Question

How does Python handle variable declaration and data types compared to languages like Java or C++?
Options
A Python requires explicit declaration of variable type before assignment, similar to Java.
B Python is more flexible; variables do not need to be declared with a particular type and can change type after being set.
Correct Answer
C Python variables are strictly bound to a unique data type upon creation and cannot be changed.
D Python uses a pre-defined set of variables, which cannot be created by the user.
Correct Answer

Option B is the correct answer.

Detailed Explanation

Page 27 notes that Python differs from Java, C, or C++ because those languages 'declare and bind a variable to a specific data type.' In contrast, page 28 states for Python: 'Variables do not need to be declared with any particular type and can even change type after they have been set.'

Hint

Compare the 'NOTE' on page 27 with the 'Creating Variables' section on page 28, especially the last bullet point.

Question Info