1

I forgot the terminology of this. In Python, if you let a=1, later you can re-assign a="letter".

But in some languages, once you let a=1, a has to stay as an integer forever.

What do we call this in textbook?

57659
  • 131
  • 1
  • 1
  • 6

2 Answers2

2

This is called statically-typed vs. dynamically-typed. In a dynamically typed language, you must define a variable with a type and it must keep that type forever.
This makes sense when you consider the meaning of the word 'static'. Something which is static is immutable i.e. is immutable. Likewise, 'dynamic' things or items can be changed freely.

For example, in C:

int x = 1;
x = "string?";

returns

error: invalid conversion from 'const char*' to 'int'

While in a language like Python, you can freely reuse variables, like this:

x = 1
x = "string?"

would return no error.

CATboardBETA
  • 418
  • 6
  • 29
-2

Dynamic typing. Also related, in Python, to weak typing.

Answer is wrong, see comments. Leaving it here as it brings value in being corrected.

caxcaxcoatl
  • 8,472
  • 1
  • 13
  • 21
  • 2
    I didn't downvote, but weak typing isn't related. Python is *strongly* typed, yet dynamically typed. C is weakly typed, yet statically typed – juanpa.arrivillaga Mar 10 '21 at 04:56
  • Thanks for the correction, @juanpa.arrivillaga. Seems like the question has been closed, so I won't bother to fix it – caxcaxcoatl Mar 10 '21 at 23:36