Learn programming for beginners
Lesson 2
Python language
Goals
● Use Cases of python .
● Writing first program using python .
● Dealing with python’s syntax .
● Comments .
● Variables .
● Datatypes .
● Casting .
Goals
● Booleans .
● Arithmetic
● Input .
● Assignment operations .
● Logic operations .
● If else statement .
Python
It is a well-known programming language that was
invented by Guido van Rossum in 1991
Python
Use cases of python
● Web development (server side) .
● software development .
● Data analysis , big data , machine learning , AI .
● Mathematics .
● Scripting …
Python
Why python ?
● Supports in various systems (windows, linux, mac os, raspberry pi ..).
● Simple syntax close to english .
● Allows to write program with less code .
● Object oriented programming language .
● Big number of libraries and open source projects .
● Used by large number of programmers around the world
● Highly demanded in job market .
Python
Writing programs using python
Printing in the screen
Launch vs code
Go to the terminal and write this command
python3 filename.py
Adding of comments
Multiline comment
Variables
How to declare variable
How to declare a string (text variable)
Capital letter sensitivity
Capital letter sensitivity
Python differentiates between lowercase and
uppercase letters meaning variable a and variable
A are not the same Variable
Names of variables
Not allowed variables name !
● Starts with number .
● Using preserved words or letters like (-,+,*,/,%) .
● Names with space .
Not allowed names
Common variable name methods
Camel case
Pascal case
Snake case
Assign value to variables
Printing in the output
You can print multiple variables using the Function
print() .
Writing in the output using print
Data types
● Natural numbers (int)
● Real numbers (float)
● Complex numbers (complex)
● Boolean (bool)
● Texts (str)
● Sets
● Dictionaries (dict)
Datatypes
Data types examples
How to know variable type ?
You can know the type of any variable in any time using the
function type(variable)
أﻧﻮاع اﻟﺒﻴﺎﻧﺎت
Data types
Casting
Python automatically assigns the data type to a
variable without having to specify it in the code
casting اﻟﺘﺤﻮﻳﻞ
What is casting ?
It is the process of converting a variable from one
data type to another
casting اﻟﺘﺤﻮﻳﻞ
Casting to integers ( natural numbers )
Casting to real numbers (float)
Casting to string
Boolean
What is a boolean ?
It is one of the data types in all programming
languages, which can be either True or False .
Boolean
Boolean
Arithmetic
Mathematic operations
Example Meaning The operation
x+y Addition +
x-y Substraction -
x*y Multiplication *
x/y Division /
x%y The rest of the %
division
x**y Power **
x//y Natural division //
Arithmetic operations
Remark
+
Addition in strings means putting the
texts together and it’s called
concatenation
concatenation
Concatenation
Data input
How to input data from the user ?
Using the keyword or the instruction :
input ()
Input
Input
This program requests the username and then writes to it
Salam elikom next to the name
Assignment operations
Operation Example Same thing
= x=3 x= 3
+= x += 1 x=x+1
-= x -=1 x = x-1
*= x *= 3 x = x*3
/= x /= 3 x = x/3
//= x //=3 x = x //3
**= x ** = 2 x = x**2
Assignment operations
Logic operations
Example Meaning Operation
x and y and and
x or y or or
Logic operations
If conditions
Different conditions cases
Operation Meaning Example
== equal a == b
!= not equal a != b
< less a<b
> greater a>b
>= greater or equal a>=b
<= less or equal a<=b
Conditions
if , else condition
In order to test a specific condition or condition if it
is true or not we use if
Conditions
if conditions اﻟﺤﺎﻻت واﻟﴩوط
elif
elif It is used in the case of adding another test
after a previous test that was tried
conditions اﻟﺤﺎﻻت واﻟﴩوط
If conditions
Else
else is used if all conditions are not met
conditions اﻟﺤﺎﻻت واﻟﴩوط
If condition
Remark
Alignment or indentation is a grandmother's task
in Syntax, the Python language, for example, this
writing is wrong:
conditions اﻟﺤﺎﻻت واﻟﴩوط
Indentation
Wrong syntax
ﺷﻜﺮا