A developer writes code to solve a business problem, irrespective of the complexity of the business problem some or a large amount of data requires processing during the execution of the programme. For processing this data, we need to store this data in memory and to store this data or information in memory data structures comes into the picture. Though it is not mandatory to know how data structure behaves internally, a high-level view of this concept would help you in solving problems and writing, optimized code. Before getting started with data structures, let us see what a variable is?
Variable is a name given to the memory location where data will reside in some data structure. We can access data from that memory location using that name. Unlike most of the programming languages like Java, C#, C, C++, Python is dynamically-typed language. Though dynamically typed languages has its cons and pros.
In Python, you need not define the data type of the variable you are going to define; it will infer the data type from the value, it has. e.g.
In the above code, did we define any data type to any variable? The answer is No, but Python is inferring the data types by the value associated with the variable name. The variable "a" is of type integer when it has 123 value, it becomes float when it has 123.45 and becomes string type when it has text value.
In the examples, we see a few variables, let us see how to define a variable in Python.
<VariableName> equal sign <value> e.g. var1=123 var2=12.23 var3="John"
While deciding name for a variable, you should be thinking descriptively so that in future when you revisit the code, you should be able to identify the purpose of the variable by its name instead of reviewing the whole code for the same reason. Apart from this basic rule, the following points you need to consider for defining a variable name:
As I mentioned earlier, apart from these rules, you should consider descriptive and readable variable names. Next, we will see different types of data structures supported by Python.