Python is a loosely typed programming language. This means that you do not have to specify the type of the variable. For example this is perfectly valid in python:
abc = “hello world”
This is a simple variable declaration that sets the string “hello world” to the variable abc. Notice that there is no indication that the variable is a string except for the actual value of the variable. In other programming languages you have to specify the type of variable (for example Java).
String abc = “hello world”;
Another thing that python has to offer is that you can change the type of the variable very quickly.
This is a quick example of how the variable “abc” was changed from a string containing “hello world” to a integer value of 10.
In the python programming language there is a simple command to print something to the screen. The comment is “print”. So when debugging a program and you cannot figure out why you are getting weird data or it is not going into a loop/if statement. Use the print statement to display the value of the variable to the console.
There are a few data types in python that will be used numerous times in these post/examples so I am going to run through a couple so you get an idea.
String —- A string is a simple value containing text. EX: “hello”
int —- A integer is a real number. EX: 10 or 5
double —- A double is a number that can have decimal values (Fractions) EX: 2.3
Next post I will get into most complex data types in python like Arrays, Lists, Stacks and Queues.