/Python is …… typed language ! #BeBsata

Python is …… typed language ! #BeBsata

The answer is : Python is “Dynamically typed” and “Strongly typed” language
but why ?! , and what’s the meaning of : Dynamically typed “and” Strongly typed ?!!!
First the opposite of Dynamically typed is : “Statically typed” , and Strongly typed is :”Weakly typed” .
Let’s know what’s the meaning of these types 🙂
 
1- Statically typed Language :

  • * The language that check the type during the compile time .
  • * it can catch many type errors early “types are fixed at compile time “
  • * Most statically typed languages enforce you to declare all variables with their data-types before using them.
  • * Ex : Java and C.

Code : In Java

here we declared the variable x as integer before assign it to 3
2- Dynamically typed Language :

  • * The language that check the type during the run time .
  • * Types are discovered at run-time .
  • * You don’t have to declare variables with their data-types before using them.
  • * Ex : Python and PHP

Code : In Python

here we assigned variable x to 3 without declaring it’s type
3- Strongly typed Language :

  • * The language which its types are always enforced .
  • * If you declared a variable as integer , you can’t do operations on it as a string ” without explicitly converting it ” .
  • * Ex : Java and Python .

Code : In Python

yes “Type error”  , because you can’t add string to int
but if you wanted to add 3 to 30 , you should convert y from string to integer

it’s 33 🙂
4- weekly typed Language :

  • * The language which its types may be ignored .
  • * if you declared a variable as string and another as integer  , you can concatenate the string ‘1’ and the integer 1 to get the string ’11’  .. “without explicitly converting it ” .
  • * Ex : Java script

Code : In Java script

yes it’s “33” as string
here : it converts integer x 3 to string x “3” ,then concatenate them (“30″+”3”) and the result is “33”
So Python is “Dynamically typed” and “Strongly typed” language 🙂 .