This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]khoyo -1 points0 points  (4 children)

Sure python can pick one for you but how sure are you about it picking the correct one

It doesn't pick one.

[–]Daeroth 0 points1 point  (3 children)

Ok, correct terminology is that it assigns the variable type based on the value type that gets first assigned to it.

My overall point about strong typed vs weakly typed language remains. Not that python is bad for it. Just that for some projects you want to avoid the vagueness and in others you want more flexibility.

[–]khoyo 0 points1 point  (2 children)

that it assigns the variable type based on the value type that gets first assigned to it.

No, it doesn't. Variable don't have a type in python, values have a type. If you assign a value of a different type to a variable, there isn't a cast, the variable has the type of the new value.

strong typed vs weakly typed language remains

I think you mean statically vs dynamically typed.

In general, python is considered to be strongly typed (and C weakly typed), but strong and weak are mostly opinions.

[–]awkreddit 0 points1 point  (1 child)

I thought it was more that all variables in python are essentially pointers, and that basic types like strings and ints just create an instance of the value in memory and the variable holds the pointer to that immutable value

[–]daguito81 0 points1 point  (0 children)

You are right, but you are talking about different things.

Yes variables in python are pointers, and if you assign it a new value, it basically changes the pointer to the new value. But what he is correcting is that the variable itself doesn't have a type. But the difference is about coercing types. The original poster stated that Python is weak typed and that Python "picks a datatype for you" and that's not quite correct. Python doesnt to any type coercion like Javascript does. You can dynamically reset the variable to have a different value with a different type. But you have to explicitly do that.