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

Introduction To Python

Uploaded by

ziaddramykamal
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

Introduction To Python

Uploaded by

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

Introduction

to python
Agenda

• Introduction
• Data Type and variables
• Conditions and loops
• Lists
• Strings
• Dictionaries
• Functions
Environment installation

1. Go to https://www.jetbrains.com/pycharm/
2. Download and Install Pycharm community version (alternatively,
you can look for PyCharm-edu version and register with your
educational-email)
3. Create a new project
1. File > New Project
2. Enter Project Name
3. Right click on the project and select New Python File
4. Write this sentence then press run
• print (“Hello Pycharm”)
What is python?
Python is a programming language.
Python is a versatile and powerful
programming language. Python is
useful for programming in a variety of
fields:
• Experience in data science and
writing system tools.
• Creating programs with graphical
user interfaces.
• Writing network-based software
Work with databases.
Data Types
• Variables actually have a type, which
defines the way it is stored.
• The basic types are:
Arithmetic
operations

Similar to actual Mathematics. Order of


precedence is the same as in
Mathematics . We can also use
parenthesis ()
Variables
• Python has no command for declaring a variable.
• A variable is created the moment you first assign a value
to it
conditions
Python supports the usual logical conditions from mathematics:
• Equals: a == b
• Not Equals: a != b
• Less than: a < b
• Less than or equal to: a <= b
• Greater than: a > b
• Greater than or equal to: a >= b
These conditions can be used in several ways, most commonly in "if
statements" and loops.
An "if statement" is written by using the if keyword.
Example
• a = 200
b = 33
if b > a:
print("b is greater than a")
elif a == b:
print("a and b are equal")
else:
print("a is greater than b")
Loops
• Python has two primitive loop commands:
• while loops
• for loops
• With the while loop we can execute a set of statements
as long as a condition is true.
A for loop is used for iterating over a sequence (that is either a list, a tuple, a
dictionary, a set, or a string).
This is less like the for keyword in other programming languages, and works more like
an iterator method as found in other object-orientated programming languages.
With the for loop we can execute a set of statements, once for each item in a list,
tuple, set etc.
break and continue Statement

• With the break statement we can stop the loop before it


has looped through all the items
• With the continue statement we can stop the current
iteration of the loop, and continue with the next
Lists

• A list is an ordered set of elements that you can add and


delete at any time.

• The element types in the list can be different. You can


access each element in the list by index. The first digit of
the index starts from 0, and the reverse index starts from-
1.
Functions of Python Lists
• cmp(list1, list2),
• len(list).
• max(list) .
• min(list) .
• list(seq)
Methods of Python Listing

list.append(o list.count(obj) list.extend(se list.index(obj) list.insert(ind


bj). . q). . ex, obj).

list.pop(obj=li list.remove(o list.sort([func


list.reverse()
st[-1]) . bj). ]).
• The pop() function removes the last element or the
element based on the index given.
• remove() function removes the first occurrence of
the specified element.
String

• In Python, a string is a Python strings may be expressed


sequence of 0 or more using single quotes, double quotes
characters, and a string is one and triple quotes, as well as
of several sequences built in escape characters, raw strings,
Python. and so on.
• In Python, strings are • name='JohnSmith‘
unchangeable and are similar to
string constants in the C and • name="Alice“
C++ languages.
• name="""Bob"""
Concatenating and slicing
strings
Dictionaries
• A dictionary is another variable container model and can store
any type of objectA dictionary is another variable container model
and can store any type of object.
• Each key value of the dictionary is separated with a colon “:" key
value pairs are separated by a comma "," and the entire
dictionary is included in the curly braces "{}".
• The key is generally unique, and the type of the key is
unchangeable. If the key repeats, the last key-value pair replaces
the previous one. Key values do not need to be unique and can
take any data type.
• A dictionary has the following format : d = {key1 : value1, key2 :
value2 }
Built-in Functions of Dictionaries
Built-in Methods of Dictionaries
Example
Functions

You can pass


A function is a
data,
chunk of code A function may
sometimes
that only return data as a
known as
executes when result.
parameters,
called.
into a function.
Example
Recursion
Recursion is a common mathematical and programming
concept. It means that a function calls itself. This has the
benefit of meaning that you can loop through data to reach a
result.

It is always made up of 2 portions, the base case and the


recursive case.
The base case is the The recursive case is the
condition to stop the part where the function
recursion. calls on itself.
Example
Hands on
Tasks
• Create a dictionary Modify the first
value in the dictionary to “First”
Print the dictionary
• Create recursive function to get
then-th Fibonacci number
• Hint : base case when n= 0 return the result
• Input : 5
• Output : Fibonacci sequence: 0 1 1 2 3
Thank you

You might also like