0% found this document useful (0 votes)
2 views61 pages

Introduction to Python Programming

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views61 pages

Introduction to Python Programming

Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

● Moatasem Elsayed

Moatasem Elsayed

● Senior Embedded Linux

● Senior Embedded Linux Software Engineer

● Embedded Software Engineer-Standard

● Embedded Software Engineer

● Embedded Linux Software Trainer


Content
Introduction
○ Goal
○ history
○ versions
○ Interpreter vs compiler
○ Start program
○ comments ○ Input
○ Python CMD ○ Operators
○ String
○ If
○ Lab1 (print)
○ Variables ○ For
○ Statically vs Dynamically
types
○ Comma operator
○ Lab2 (arithmetic
equations )
○ Data Types
Goal
Tools
Introduction To Python

1
2 ∗ Python is a popular programming language created by Guido
3 van Rossum in 1991
4
5 ∗ Python works on different platforms (Windows, Mac, Linux)
and it has a simple syntax similar to the English language
6
7 ∗ major version of Python is
8 Python 3 . Python 2
9
10
11
12
13
14
Python Versions

1
2 ∗ After installation of python and add to path variable
3
4
5
6
7
8
9
10 ∗ Open cmd and write this command Python --version
11
12
13
14
Interpreter Vs Compiler

1
2 Python is an interpreted programming language not compiler
3
4
5
6
7
8
9
10
11
12
13
14
Python Interpreter

1
What is bytecode?
2
Bytecode3is computer object code that an interpreter converts
into binary machine code so it can be read by a computer's
4
hardware processor.
5
6
The interpreter is typically implemented as a virtual machine
(VM) that translates the bytecode for the target platform. The
7
machine code consists of a set of instructions that the processor
8
understands.
9
10
11
12
13
14
How to Run interpreting ?
1
2
3
4
5
6
7
8 OR
9 Shebang
10
11
12
13
14
Comments

1
2
1- No Semicolons
3 # this is comment
4 print(“hello”) 2- Internal functions
5
have don t need a
6
7
library to include
8
9 Comments : 3- space is very
10 1- # for single line important
11
2- ‘ ‘ ‘
12 Multi lines
13 ‘ ‘ ‘
14
String
1
2
3
4
5
6
7
8
9
10
11
12
13
14
Quick Task (print)

1 Write a python code that print your information.


2 Full Name, Birth Year, Faculty, E-mail, Address
3
4
5
6
7
8
9
10
11
12
13
14
Variables
1 Unlike other programming languages, Python has no command for declaring a
2 variable. A variable is created the moment you first assign a value to it.
3
4
5
6
7
8
9
10
11
12
13
14
Statically vs Dynamically types

1 Statically typed languages


2 A language is statically typed if the type of a variable is known at compile time. For some languages this
3 means that you as the programmer must specify what type each variable is; other languages (e.g.: Java,
C, C++)
4
5
6
Dynamically typed languages
7
8 A language is dynamically typed if the type is associated with run-time values, and not named
variables/fields/etc. Examples: Perl, Ruby, Python, PHP, JavaScript, Erlang
9
10
11
12
13
14
Variable naming rules

1 A variable starts with a letter or the underscore ( _ )character


2 A variable cannot start with a number
A variable only contains alphanumeric characters and underscores (A z, 0 9 , and _)
3
Variables are case sensitive (age, Age and AGE are three different variables)
4
5
6
7
8
9
10
11
12
13
14
Same as C/C++
Comma Operator
1
2
3
4
5
6
7
8
9
10
Same concept in c++14
11
12
13
14
Quick task Arithmetic
1
2 Print sum of two numbers
3
4 Print sub of two numbers
5
6 Print Div of two numbers
7
8 Print Mult of two numbers
9
10
11
12
13
14
Data Types
1
2
3
4
5
6
7
8
9
10
11
12
13
14
Data Types

1
2
3
4
5
6
7
8
9
10
Tuple =const list
11
12
13
14
bool
1
2
3
4
5
6
7
8
9
10
11
12
13
14
list Collection - ordered - mutable

1
2
3
4
5
6
7
8
9
10
11
12
13 Slicing
14 bash
Tuple

1
Collection ordered unchangeable
2
(Immutable)
3
4
5
6
7
8
9
10
11
12
13
14
Dictionary

1
2
Json
3
4
5
6
7
8
9
10
11
12
13
14
No Duplicate Member

1
2
3
4 python
5
6
7
8
9
10
11
12 C++: map
13 Go: map
14 Rust: HashMap
Javascript: object
set

1 items are unordered, changeable(mutable), and do not allow duplicate values.


2
3
4
5
6
7
8
9
10
11
12 C++: unordered_set
13
14
Hash table

1
2
3
4
5 search
6
7
8
9
10
11
12
13
14
Range

1
2
3
4
5
6
7
8
9
10
11
12
13
14
Main Comparison

1
2
3
4
5
6
7
8
9
10
11
12
13
14
Convert string to list
1
2
3
4
5
output
6
7
8
9
10
11
12
13
14
Input

1
2
3
4
5
6
7
8
9
10
11
12
13
14
Operators
1
2
3
4
5
6
7
8
9
10
11
12
13
14
Arithmetic

1
2
3
4
5
6
7
8
9
10
11
12
13
14
Comparison Operators
1
2
3
4
5
6
7
8
9
10
11
12
13
14
Assignment Operators

1
2
3
4
5
6
7
8
9
10
11
12
13
14
Logical Operators

1
2
3
4
5
6
7
8
9
10 C++
11
12
ERROR RUN
13
14
C
Bitwise(with mentor)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
Membership Operators
1
2
3
4
5
6
7
8
9
10
11
12
13
14
Identity Operators

1
2
3
4
5
6
7
8
9
10
11
12
13
14
If condition
1
2
3
4
5
6
7
8
9
10
11 Shorthand If
12
13
14
Shorthand If ... Else

1
2
3
Idea is the true statement comes before condition
4
5
6
7
8
9
10
Ternary
11
12
13
14
Nested if
1
2
3
4
5
6
7
8
9
10
11
12
13
14
pass Statement

1 a = 33
2
3 b = 200
4
5
if b > a:
6 pass Like empty
7
bracket
8
9
10
11
12
13
14
loop
While Loop for
1
2
3
4
5
6
7
8
9
10
11
12
13
14
Break vs continue

1
2
3
4
5
6
7
8
9
10
11
12
13
14
Else in For Loop Nested Loops

1
2
3
4
5
6
7
8
9
10
11
12
13
14
Shorthand for

1
2
3
4
5
6
7
8
9
10
11
12
13
14
Reverse string

1
Write a python code that ask the user to enter a sentence and then print it in
2
opposite direction
3
4
5
6
7
8
cstyle Python style
9
10
11
12
13
14
Useful Scripts
Import modules

1
2
3
4
5
6
7
8
9
10
11
12
13
14
Favourite Folder
1
2
3
4
5
6
7
8
9
10
11
12
13
14
Time Now

1
2
3
4
5
6
7
8
9
10
11
12
13
14
pyfiglet

1
2
3
4
5
6
7
8
9
10
11
12
13
14
requests

1
2
3
4
5
6
7
8
9
10
11
12
13
14
Youtube Downloader
1
2
3
4
5
6
7
8
9
10
11
12
13
14
Install Module

1
2
3
4 😡
5
6
7
8
9
10
11
12
13
14
😀
Big Problem (Take Care)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
Convert text to speak
1
2
3
4
5
6
7
8
9
10
11
12
13
14
Tasks
1 Write a Python program to count the number 4 in a given list.
2
3
4
5
6 Write a Python program to test whether a passed letter is a
7 vowel or not.
8
9
10
11
12 Write a python program to access environment variables.
13
PATH os
14
Tasks(2)

1 Write a Python program which accepts the radius of a circle from the user and compute the
2 area.
3
4
5
6
7
8
9
10
11
12
13
14
Tasks(3)

1
Print the calendar of a given month and year
2
3
4
5
6
7
8
9
10
11
12
13
14

You might also like