0% found this document useful (0 votes)
5 views

Intro to Python

Uploaded by

nadianairat1eng
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Intro to Python

Uploaded by

nadianairat1eng
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 15

intro to

python
present by:
Nadia Nairat
Overview
• what is python.
• Data types
• variables
• syntax error
• How to get an input from the
user?
What's python?
python
is:
Python is an
interpreted, object-
oriented, high-
level programming
language with
dynamic
case-sensitive
semantics.
if you write:
a not the same to
A
• why you
should learn
python? • where it can
where it can be
used:
• a clear easy code
be used?
to understand .
• we can easily
change and play
with a sires of • AI and machine
code . learning
• it can work with • web development
any operation • game development
system. • data visualization
• data analytics
• language
development
Data types:
1- Numbers
2- String, ex: "Rahaf"
3- List, ex: ["Lama", 2, "Ahmed",
4]
4- Tuple, ex: ("Lama", 2,
"Ahmed", 4)
5- Dictionary, ex: {"Ghala":19}
variable
s:
variables How to declare a variable ?
are piece of information Nameofvariable = theexpression or
that can the value
change in a later Ex: y = 56 or 4*7
statement. A python Note: in programming languages we
variable is a reserved used one equal sign ( = ) to assign
values to variables. It doesn’t mean
memory location to store
equality as in algebra we used 2 equal
values. sign ( == ) to indicate an equality, ex:
if ( x==2 )
Rules for creating variables in Python:

• A variable name must start with a letter


or the underscore character.
• A variable name cannot start with a
number.
• A variable name can only contain alpha-
numeric characters and underscores (A-
z, 0-9, and _ ).
• Variable names are case-sensitive
(name, Name and NAME are three
different variables).
• The reserved words(keywords) cannot
be used naming the variable.
Quick quiz ( true or
false )
M-1
2x
g_8
else
H4
what is syntax error:
Syntax errors are similar to grammar or spelling
errors in a Language. If there is such an error in
your code, Python cannot start to execute your
code. You get a clear error message stating what

syntax error is wrong and what needs to be fixed. Therefore, it


is the easiest error type you can fix.

Exampels:
Missing symbols (such as comma, bracket, c
olon), misspelling a keyword, having incorrec
t indentation
.are common syntax errors in python.
How can we get an
input from the user: Variable = input (“ ” )
Ex: age = input (“Enter your age”)

Ex: age = input (“Enter your age”)


int ( age )

Ex: age = input (“Enter your age”)


float ( age )

Ex: age = input (“Enter your age”)


Eval ( age ) and the python intrepreter will choose the appropriate
type

Ex: age = eval (input (“Enter your age”))


Ex: age = float (input (“Enter your age”))
Ex: age = int (input (“Enter your age”))
let's start
coding
"hello"+"world" "helloworld"
4+6 =10 # concatenation
"4"+"6" =46

hello"*3 "hellohellohello" # repetition

•"hello"[0] "h" # indexing

"hello"[1:4] "ell" # slicing

•len("hello") 5 # size

type(5) class'int' #type


If - else and loop:

if - else : While loop:


a conditions can be used in With the while loop we can execute a
several ways, most commonly set of statements as long as a
condition is true.
in "if statements" and loops.
Note: remember to increment i, or
The elif keyword is pythons
else the loop will continue forever.
way of saying "if the previous
or you can put a break statement
conditions were not true, then
try this condition".
i=1
a=2 i=1
counter = 1while (counter < 5): while i < 6: while i < 6:
b = 330 print(i)
print(i)
if a > b: count = counter i += 1
if i == 3: else:
print("A") if count < 2: break print("i is no longer
i += 1 less than 6")
else : counter = counter + 1else:
print("B")
print('Less than 2')
if count > 4:
counter = counter + 1else:
print('Greater than 4')
counter = counter + 1
intro to
python
thank you
for listening

never stop coding

You might also like