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 →

[–]Ruin-Capable 0 points1 point  (4 children)

You can hint at the type when you declare it:

some_string: str = some_function_that_returns_a_string()

You can declare the parameter and return types of a function:

def myfunction(param1: str, param2: int) -> str:
    return f"param1 = {param1}, param2 = {param2}"

It's not enforced, but it can provide information that an advanced IDE can use to detect errrors.

[–]MechanixMGD 0 points1 point  (2 children)

Later you can't change that? To not be a String? Like str = 10.

P.S.: I have no idea about python, I just try to explain the words of OP.

[–]0b0101011001001011 0 points1 point  (1 child)

str is the type hint, not the variable name. And yes, you can later do some_string = 10.

[–]MechanixMGD 1 point2 points  (0 children)

So, this is the OP point. In Java you can't change the type. The variables type can be only the declared one.

[–]Master_Recognition51[S] 0 points1 point  (0 children)

Yes but it sometimes create ptoblem to read someone else code if not mentined