Python Tutorial: Why There Is No Type Declaration in Python

Pubblicato il: 05 marzo 2015
sul canale di: 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.


In questa pagina del sito puoi guardare il video online Python Tutorial: Why There Is No Type Declaration in Python della durata di ore minuti seconda in buona qualità , che l'utente ha caricato Code master 05 marzo 2015, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 6,762 volte e gli è piaciuto 46 spettatori. Buona visione!