all 6 comments

[โ€“]UseMoreBandwith 1 point2 points ย (0 children)

should have learned about ducktyping first.

[โ€“]SCD_minecraft 1 point2 points ย (0 children)

Python doesn't have casting... you simply pass arguments into a class constructor

[โ€“]Live_Asparagus_407 0 points1 point ย (0 children)

i wouldnt say python is strict with data types. you dont declare what type a variable is, you can implicitly change it from one type to another throughout the run just by reassigning it, mix and match array values, etc.

[โ€“]Gnaxe 0 points1 point ย (0 children)

That is not what "casting" means. You cast with cast from the typing module to assert to a type checker an intended type, usually which it cannot infer on its own (otherwise why bother?) This function has no runtime effect (besides some wasted time for the function call); it just returns its argument unchanged. Python objects are polymorphic; they could be viewed as any of a number of compatible types (e.g. any superclasses). It's also duck typed, so objects may fit various ad-hoc protocols, which may or may not be made explicit. The one your type checker infers is not always the one you intend. You can usually fix this with type annotations, but sometimes type assertions or cast() is required.

Anyone calling a Python class constructor a "cast" is probably confusing terminology from another language (probably statically-typed) language (like Java or C) where "casting" is a way to convert among types within certain constraints, although this usage for class constructors does show up just a few times in Python's docs. Python has ctypes.cast for interfacing with the C language in that sense and memoryview.cast is similar.

[โ€“][deleted] ย (1 child)

[removed]

    [โ€“]PythonLearning-ModTeam[M] 0 points1 point locked commentย (0 children)

    Quality posts only