A note on dictionaries in Programming languages

I recently started with learning python. The good thing about python is that everything in python is dynamic. Python is dynamically typed language. What does it means?
In C/C++ or Java we need to define the type of a variable before using it.
int a; 
float b;
// even Objects need to be defined in
Matrix m1;

But, python is different in this regard. Here, we can use a variable and its type is decided on first assignment.

list  # not needed but just for explanation

list = [] # creates an empty list


Thus, Python decides the type of a variable on its first assignment making it dynamically typed. But, another thing to be careful with in it is that Python is also strongly typed language. Means, once assigned we cant change the type of that variable. In, above python code once list varible is assigned an list object it cant be assigned any other data type. It remains list.


Below, is the summarization of different types of languages based on the property we just discussed.

statically typed language

A language in which types are fixed at compile time. Most statically typed languages enforce this by requiring you to declare all variables with their datatypes before using them. Java and C are statically typed languages.

dynamically typed language

A language in which types are discovered at execution time; the opposite of statically typed. VBScript and Python are dynamically typed, because they figure out what type a variable is when you first assign it a value.

strongly typed language

A language in which types are always enforced. Java and Python are strongly typed. If you have an integer, you can't treat it like a string without explicitly converting it.

weakly typed language

A language in which types may be ignored; the opposite of strongly typed. VBScript is weakly typed. In VBScript, you can concatenate the string '12' and the integer 3 to get the string '123', then treat that as the integer 123, all without any explicit conversion.


1 comment:

  1. Nice to see ur working on python these days.
    I have also found some interest in the same..
    LearnPythonTheHardWay.com
    check this site, consists of one pdf very good for understanding.

    ReplyDelete