Python is Dynamic!
One of the advantages of using the
Python language is that
any variable can dynamically
hold values of different types throughout a program, without requiring type declaration as in
initialization in C++.
The following code is already executed:
What do we notice? Initially, the variable
n held the
integer value 123.
Then it was assigned a
string "
Python", and finally a
float value 23.25. After each assignment,
we displayed the current value of the variable
n.
Even the colors in the Python editor change because
the data types differ ... 🧐
Additionally, we encountered our first issue when we tried to add two numbers entered from the keyboard.
By default, the
input function takes the input and returns it as a string for
manipulation in our code -
2 +
3 doesn't equal
23!
It's time to study these
data types!
Proceed to the next page of the lesson.