PYTHONOTES
PYTHONOTES
Python is one of the world's easiest and most popular programming languages. It can
be used for almost anything, including:
Web development
Game development
Artificial intelligence
Operating systems
Desktop applications
And more.
Python is considered a very powerful language due to its large community and many
built-in libraries. Read more
This course will teach you the basics of Python, without requiring any prior
knowledge.
Hello World!
The "Hello World!" is a simple program that outputs Hello World! to the screen.
Numbers
Variables are containers that hold data values. They are used to store, manipulate, and
display information within a program.
In short a variable is like a memory unit that we can access by typing the name of the
variable.
Each variable has a unique name and a value that can be of different types. Python is
capable of automatically detecting the variable type, which makes coding more
efficient.
We initialize a variable of type int with the name a and the value 3 .
We initialize a variable of type float with the name b and the value 13.2 .
a = 3
b = 13.2
String
A char is a single character (For example: 1, 6, %, b, p, ., T, etc.)
The str (string) type is a special type that consists of multiple chars.
Boolean
A bool (Boolean) type has only 2 possible values: True or False .
variable_false = False
In the above example, two variables named variable_true and variable_false are
initialized, with the values True and False respectively.
Booleans are the building blocks for creating logic in the programs we write. We
have a whole chapter about logic and conditions.
Arithmetic operators
Operators used to perform operations on values.
First we will discuss the most basic arithmetic operators, they may be familiar from
math classes.
+ Addition 3+2=5
- Subtraction 3-2=1
* Multiplication 3*2=6
/ Division 4/2=2
Modulus operation provides the remainder that results from dividing the first value
by the second value.
For example:
14 % 4 returns 2 because 4 can be inserted into 14 three times (4*3 = 12) and now 14
minus 12 equals 2 (The remainder).
Arithmetic shortcuts
Python created a cool shortcut for self-arithmetic operations.
a = 5
a += 3 # a hold 8
Operato
Shortcut
r
+ +=
- -=
* *=
/ /=
% %=
Comparison Operators
Comparison operators is used to compare between two operands.
Greater or
>= 1 >= 2 return false
Equal
The comparison operator returns True if the comparison is correct or False otherwise.
For example:
var1 = 13
var2 = 12
var3 = var1 != var2
var3 will hold True because var1 and var2 are not equal