5 misunderstood concepts in Python
Python programming language is useful for a lot of different beginner, mid-level and experience programmers, but if someone has their first go at Python there might be some spots where they feel stuck which has no detailed description.
Assignment of Variables
Whenever a variable is given a value, that is called assignment to the variable, although there must be different aspects that must be kept in mind when analyzing assignment. Being a variable a space in memory whose content represents its value the assignment may be one of several operations.
When we talk about literal, it means the value on the right side of the equals operator is assigned to the left variable.
In other different cases there are major difference between Python and other programming languages. The assignment between two variables of a base type represents a copy of the value. This enables the values of data types like strings, int, float, Boolean are copied from right to left variables.
Declaration and Instantiation of Variables
The declaration is directly related to the existence of a variable. This is called as instantiation which means the creation of space in memory that allows the memory to hold a variable value. Moreover, this is commonly done with a declaration of the type of the variable (numeric, string, etc.).
In python the need to explicitly declare a variable has no requirement. It contains instantiation and declaration at assignment implicitly, without declared type.
Typing in Python
The space in which data is held in memory and the characteristics of variables is referred to as typing. At instantiation, the program requests the allocation of a memory block to hold the variable, so that information is then used.
Python uses duck-typing. This referres to the concept that the variable has a specific type that is created at the assignment o the variable but when that variable is used, there is no need for any specific type. The operation that is performed is legal. An example can be: If it quacks like a duck and it walks like a duck, then it is probably a duck — and so Python treats it as such.
Python’s Memory Management
Python has pre-defined rules for memory management. They include implicit memory allocation, manipulation, and release.
In addition to this, the garbage collector frees unused variables when the scope is completed. This can result in some useless variables, which can also be big variables, still stand in the memory and this leads to experiencing an out-of-memory issue when instantiating any small harmless variable.
Looping, Iterators, and Generators
has only two types of loops: while and for ... in. Still, they generate great confusion when compared with the other programming languages.
When it is compared with C, while has the exact same behavior, it allows the checking of a Boolean condition and exits immediately if it is not matched. However, for is completely different: in C the code block is repeated based on an initial condition, which results is execution of an increment at every step, this depends on as long as if theBoolean condition is met; in Python it executes the code block on a sequence of elements, exiting when they are over.
Wrapping Up
So, if you are learning, and you go for Python beware of its eccentricities, and it is better to use a guide, you may avoid the effort of understanding subordinate issues. But it is very likely you will pay the price later, when you become more experienced and do more complex things.