Introduction

Python is a high-level programming language that is well known and widely used in science and engineering fields. It is user-friendly and allows users to interact with a computer using simple English phrases instead of complex assembly or binary commands.

As a high-level programming language is more readable than other programming languages that are more oriented to machine logic. One of the particularity presents in python is that variable types are not declared before using them, this is called dynamic typing, and it is useful to better understand the code and debugging.

Variables and Types

The Python ease comes from the fact that it’s object-oriented, meaning you don’t need to declare the variables before using them because they are objects already.

Let’s explore how it works and have some fun with it. The first step is to understand the variables and types.

Numbers :

it can support two types of numeric variables’ integer (whole numbers) and floating point (decimals) and also complex numbers. The syntax for those is ease to show.

Integers

Integers are represented by the function int().

1
2
3
a = int(1)
b = int(2.5)
print(a,b)
output:
1
1 2

Floats

Float are represented by the function float()

1
2
3
a = float(1)
b = float(2.5)
print(a,b)
output:
1
1.0 2.5

Complex

For the complex numbers, the function complex() accepts two parameters, the first is for the real part and the second one is for the imaginary part.

1
2
3
a = complex(1)
b = complex(2,5)
print(a,b)
output:
1
1+0j 2+5j

As shown another way to define variables is the easiest one, just write them down as it, they will be interpreted as their type.

1
2
3
4
a = 1
b = 2.5
c = 3+5j
print(a, b, c)
output:
1
1, 2.5 3+5j

Strings

Other programming languages treats the letters and words differently, as single letter (characters/char) and words (strings). In Python, they are treated similarly as strings, which is the function for it string() another technic to use is to enclose them between quotation marks single (’ ‘) and doubles(" “). The difference between the two is that using double quotes makes easy to include apostrophes.

1
2
3
a = string(my code here)
b = "also this can be my code"
print(a, b)
output:
1
my code here also this can be my code

We had mentioned variable definition. What does that mean in simple English? It is quite different at the math variable we all know, first Python is capital sensitive, which means that this and This are different strings, second variables must be equal to something or none, otherwise x= will produce an error, best practices is to set it to none x= None.

1
2
x = None
print(x)
output:
1
None