Python Tutorial: Why There Is No Type Declaration in Python

Veröffentlicht am: 05 März 2015
auf dem Kanal: Code master
6,762
46

See the full tutorial at http://learnpythontutorial.com/why-th...
Why There is No Type Declaration in Python
If you have learned other programming languages like Java or C you may a bit confused why we can declare a variable without giving that variable a type. If Python is your first language, then you may not. Python is smart enough to find out our types when we declare a variable in our programs. If Python can find out what type of data we are using in our code then why would we waste our time declaring types of variables?

The Reason Why There is No Type Declaration in Python
The reason why we do not have to give a variable a type declaration is because the variable does not contain any information. In the previous tutorial, we discussed that variables are just pointers or they just reference a section of memory called an object. The object contains the type information, the value that was given and a reference counter.

Why Does The Object Hold Type Information?
The object holds the type information to save memory and accelerate your programs. If we created several variables with the exact same value then these variables are just pointing to one memory space. If the variables held the type information and values then we would be using a lot more memory in our programs which would slow down the program. In this day and age everyone wants programs to run at high speed. So when an object holds the information we can cut down on memory used.


Auf dieser Seite können Sie das Online-Video Python Tutorial: Why There Is No Type Declaration in Python mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Code master 05 März 2015 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 6,762 Mal angesehen und es wurde von 46 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!