Lecture 1
(Python Fundamentals)
Prepared by:
Ahmed Elhoseiny
Agenda
⚫ What is Python?
⚫ Why Learn Python?
⚫ Install Python and Visual Studio code
⚫ Syntax
⚫ Comments
⚫ Variables(Names, Multiple Variables, Input & Output Variables)
⚫ Data Types
⚫ Numbers
⚫ String(Concatenation, Format, Escape Characters )
⚫ Booleans(Most Values are True, Some Values are False)
⚫ Operators(Arithmetic, Assignment, Comparison, Logical )
What is Python?
⚫ Python is a popular programming language. It was
released in 1991.
⚫ It is used for:
- AI and Machine Learning
- Data Analysis and Visualization
- Web Development
- Software Development
- Etc.….
Why Learn Python?
⚫ Python works on different platforms (Windows, Mac, Linux,
etc).
⚫ Python has a simple syntax similar to the English language.
⚫ Python has syntax that allows developers to write programs
with fewer lines than some other programming languages.
⚫ Python runs on an interpreter system, meaning that code can be
executed as soon as it is written. This means that prototyping
can be very quick.
Install Python and Visual Studio code
⚫ Python: https://www.python.org/downloads
⚫ Visual Studio code: https://code.visualstudio.com
Complier Online:
⚫ 1- https://www.programiz.com/python-programming/online-compiler/
⚫ 2- https://www.onlinegdb.com/online_python_compiler
Syntax
⚫ Variables Types
⚫ Basic Operators
⚫ If…Else
⚫ Loops
⚫ Numbers
⚫ Strings
⚫ Lists
⚫ Function
⚫ Classes & Objects
Comment
⚫ Comments can be used to explain Python code.
⚫ Comments can be used to make the code more readable.
⚫ Comments starts with a #
⚫ you can add a multiline string (triple quotes) (""" ""“)
Variables
⚫ Variables are containers for storing data values
Variables(Names)
⚫ A variable can have a short name (like x and y) or a more
descriptive name (age, carname, total_volume). Rules for
Python variables:
⚫ A variable name must start with a letter (A-z) or the underscore character(_)
⚫ A variable name cannot start with a number(0-9)
⚫ A variable name can only contain alpha-numeric characters and underscores
(A-z, 0-9, and _ )
⚫ Variable names are case-sensitive (age, Age and AGE are three different
variables)
⚫ A variable name cannot be any of the Python keywords.
Python keywords
Variables(Multiple Variables)
⚫ Python allows you to assign values to multiple variables in
one line:
Variables(Input & Output )
⚫ Python allows for user input.
Variable = input()
⚫ In the print() function, you output multiple variables
print(var1,var2,var3)
⚫ You can also use the (+) operator to output multiple
variables
print(var1+var2+var3)
Data Types
Numbers
⚫ There are three numeric types in Python:
1. Int: is a whole number, positive or negative, without decimals, of unlimited length.
2. Float: is a number, positive or negative, containing one or more decimals.
⚫ You can convert from one type to another with the int()
and float()methods
String
⚫ Strings in python are surrounded by either single quotation
marks (' '), or double quotation marks(" ").
⚫ You can use quotes inside a string, as long as they don't
match the quotes surrounding the string
⚫ Assigning a string to a variable is done with the variable
name followed by an equal sign and the string
⚫ You can assign a multiline string to a variable by using
three quotes (""" """)Or three single quotes(' ' ' ' ' ')
String (Concatenation)
⚫ To concatenate, or combine, two strings you can use the +
operator.
String(Format)
⚫ As we learned in the Python Variables chapter, we cannot combine strings
and numbers
⚫ But we can combine strings and numbers by using f-strings or
the format() method!
⚫ It was introduced in on December 23, 2016
⚫ To specify a string as an f-string, simply put an f in front of the string literal,
and add curly brackets {} as placeholders for variables and other operations.
⚫ A modifier is included by adding a colon : followed by a legal formatting
type, like .2f which means fixed point number with 2 decimals
⚫ A placeholder can contain Python code, like math operations
String(Escape Characters)
⚫ To insert characters that are illegal in a string, use an
escape character.
⚫ An escape character is a backslash \ followed by the
character you want to insert.
Booleans
⚫ Booleans represent one of two values: True or False.
⚫ In programming you often need to know if an expression
is True or False
⚫ You can evaluate any expression in Python, and get one of
two answers, True or False.
⚫ The bool() function allows you to evaluate any value, and
give you True or False in return
Booleans (Most Values are True)
⚫ Almost any value is evaluated to True if it has some sort
of content.
⚫ Any string is True, except empty strings.
⚫ Any number is True, except 0.
⚫ Any list, tuple, set, and dictionary are True, except empty
ones.
Booleans (Some Values are False)
⚫ In fact, there are not many values that evaluate to False,
except empty values, such as (), [], {}, "", the number 0,
and the value None. And of course the
value False evaluates to False.
Operators(Arithmetic)
⚫ Operators are used to perform operations on variables and
values.
Operators(Assignment)
⚫ Assignment operators are used to assign values to
variables
Operators(Comparison)
⚫ Comparison operators are used to compare two values
Operators(Logical)
⚫ Logical operators are used to combine conditional
statements
Assignment
⚫ 1- Install Python and Visual Studio code
⚫ 2- Write a program to read two integers(by user) and
perform arithmetic operations on them (addition,
subtraction, multiplication and division).
⚫ 3- Code for rectangle perimeter (by user)
⚫ 4- Code for circle circumference (by user)
Questions ?