SlideShare a Scribd company logo
1
By: Yosef Nigussie
Python Basics
2
Python Basics
Basic Syntax
 .
3
Python Variables
 Variables are nothing but reserved memory
locations to store values. This means that when
you create a variable you reserve some space in
memory..
 Python variables do not need explicit declaration
to reserve memory space. The declaration
happens automatically when you assign a value to
a variable.
 python allows you to assign a single value to
several variables or multiple objects to multiple
variables simultaneously.
4
a = b = c = 1
a,b,c = 1,2,"john"
Data types
 Python has five standard data types
 Numbers
 String
 List
 Tuple
 Dictionary
5
Python Numbers
 Python supports four different numerical types:
 int (signed integers)
 long (long integers, they can also be
represented in octal and hexadecimal)
 float (floating point real values)
 complex (complex numbers)
6
var1 = 1 var2 = 10
del var del var_a, var_b
Python Strings
 Strings in Python are identified as a
contiguous set of characters represented in
the quotation marks.
 Python allows for either pairs of single or
double quotes. Subsets of strings can be taken
using the slice operator ([ ] and [:] ) with
indexes starting at 0 in the beginning of the
string and working their way from -1 at the
end.
 The plus (+) sign is the string concatenation
operator and the asterisk (*) is the repetition
operator.
7
8
Example
User inputs:
 Enter your name: John
 Enter your age:25
Out put:
 Welcome, John ! you are now 25
Write a program which accepts name and age input from
user and print it?
Python Operators
 Assignment operators(=)
 Arithmetic operators(+,*,/,-)
 Comparison operators(<,>,<=)
 Logical operators(and, or, not)
 Bitwise operators(^,&,|)
 Data Type Conversions: Implicit or explicit
9
10
Arrays
 An array is a data structure consisting of a collection of elements
(values or variables), each identified by at least one array index
or key
 Arrays and Lists
 Index Notation
 Displaying Array Members
 Multidimensional Arrays
Python Lists
 The most basic data structure in Python is
the sequence. Each element of a
sequence is assigned a number - its
position or index. The first index is zero,
the second index is one, and so forth.
 The list is a most versatile datatype
available in Python which can be written
as a list of comma-separated values
(items) between square brackets.
Important thing about a list is that items
in a list need not be of the same type.
 Lists are mutable objects that can change
their values 11
list1 = ['physics', 'chemistry', 1997,
2000]; list2 = [1, 2, 3, 4, 5 ]; list3 =
["a", "b", "c", "d"]
Python Lists
 Accessing Values in Lists: use
the square brackets for slicing
along with the index or indices
to obtain value available at that
index.
 Updating Lists: You can update
single or multiple elements of
lists by giving the slice on the
left-hand side of the assignment
operator, and you can add to
elements in a list with the
append() method.
12
Python Lists
 Delete List Elements: To remove a
list element, you can use either the
del statement if you know exactly
which element(s) you are deleting
or the remove() method if you do
not know.
 Basic List Operations: Lists respond
to the + and * operators much like
strings; they mean concatenation
and repetition here too, except
that the result is a new list, not a
string.
13
Python Lists
 Common List functions
14
Python Lists
 Common list
methods
15
Tuples
 A tuple is a collection of
objects which ordered
and immutable.
 The differences between
tuples and lists are, the
tuples cannot be
changed unlike lists and
tuples use parentheses,
whereas lists use square
brackets.
16
tup1 = ('physics', 'chemistry',
1997, 2000);
tup2 = (1, 2, 3, 4, 5 );
tup3 = "a", "b", "c", "d";
Tuples
 Accessing Values in Tuples
 Updating Tuples
 Delete Tuple Elements
 Basic Tuples Operations: Tuples
respond to the + and *
operators much like strings;
they mean concatenation and
repetition here too, except
that the result is a new tuple,
not a string.
17
Tuples
 Built-in Tuple
Functions
18
Dictionaries
 Each key is separated from its value by a colon (:), the items are
separated by commas, and the whole thing is enclosed in curly
braces.
 Keys are unique within a dictionary while values may not be. The
values of a dictionary can be of any type, but the keys must be of an
immutable data type such as strings, numbers, or tuples.
19
Dictionaries
 Accessing Values in Dictionary
 Updating Dictionary
 Delete Dictionary Elements
20
Dictionaries
 Properties of Dictionary Keys
 More than one entry per key
not allowed. Which means
no duplicate key is allowed.
 Keys must be immutable.
21
dict = {'Name': 'Zara', 'Age': 7, 'Name':
'Manni'}
print "dict['Name']: ", dict['Name']
dict = {['Name']: 'Zara', 'Age': 7} print
"dict['Name']: ", dict['Name']
Dictionaries
 Built-in Dictionary Functions & Methods
22
Dictionaries
 Dictionary
methods
23

More Related Content

Similar to Chapter 2-Programming Basics and Arrays.pptx Chapter 2-Programming Basics and Arrays.pptx (20)

PPTX
Python variables and data types.pptx
AkshayAggarwal79
 
PPT
Getting started in Python presentation by Laban K
GDSCKYAMBOGO
 
PPTX
Python Workshop
Assem CHELLI
 
PPTX
UNIT-3 python and data structure alo.pptx
harikahhy
 
PDF
Basics of Python and Numpy_583aab2b47e30ad9647bc4aaf13b884d.pdf
RudysBeats1
 
PPT
Python lab basics
Abi_Kasi
 
PDF
Datatypes in Python.pdf
king931283
 
PPTX
1691912901477_Python_Basics and list,tuple,string.pptx
KUSHSHARMA630049
 
PPTX
"Sequences in Python include list, tuple, string, and range"
KeerthiKeerthi618086
 
PDF
ppt_pspp.pdf
ShereenAhmedMohamed
 
PDF
Python Variable Types, List, Tuple, Dictionary
Soba Arjun
 
PPTX
Python- Basic. pptx with lists, tuples dictionaries and data types
harinithiyagarajan4
 
PPTX
Python- Basic.pptx with data types, lists, and tuples with dictionary
harinithiyagarajan4
 
PPTX
1. python programming
sreeLekha51
 
PPTX
Data Structures in Python
Devashish Kumar
 
PPTX
IOT notes,................................
taetaebts431
 
PPTX
Python
reshmaravichandran
 
PPTX
Python data type
Jaya Kumari
 
ODP
Python slide.1
Aswin Krishnamoorthy
 
PDF
"Automata Basics and Python Applications"
ayeshasiraj34
 
Python variables and data types.pptx
AkshayAggarwal79
 
Getting started in Python presentation by Laban K
GDSCKYAMBOGO
 
Python Workshop
Assem CHELLI
 
UNIT-3 python and data structure alo.pptx
harikahhy
 
Basics of Python and Numpy_583aab2b47e30ad9647bc4aaf13b884d.pdf
RudysBeats1
 
Python lab basics
Abi_Kasi
 
Datatypes in Python.pdf
king931283
 
1691912901477_Python_Basics and list,tuple,string.pptx
KUSHSHARMA630049
 
"Sequences in Python include list, tuple, string, and range"
KeerthiKeerthi618086
 
ppt_pspp.pdf
ShereenAhmedMohamed
 
Python Variable Types, List, Tuple, Dictionary
Soba Arjun
 
Python- Basic. pptx with lists, tuples dictionaries and data types
harinithiyagarajan4
 
Python- Basic.pptx with data types, lists, and tuples with dictionary
harinithiyagarajan4
 
1. python programming
sreeLekha51
 
Data Structures in Python
Devashish Kumar
 
IOT notes,................................
taetaebts431
 
Python data type
Jaya Kumari
 
Python slide.1
Aswin Krishnamoorthy
 
"Automata Basics and Python Applications"
ayeshasiraj34
 

More from YosefNigussie2 (16)

PPTX
Chapter 4-database backup and recoveryProgramming Functions.pptx
YosefNigussie2
 
PPTX
OSS1 OSS1 OSS1 OSS1 OSS1 OSS1 OSS1 OSS1.pptx
YosefNigussie2
 
DOCX
excel practice-0.0.docx excel practice-0.0.
YosefNigussie2
 
DOCX
excel practice-0.0.docx excel practice-0.0. excel practice-0.0.
YosefNigussie2
 
DOCX
excel practice-1.0.docx excel practice-1.1. excel practice-1.1.
YosefNigussie2
 
DOCX
excel practice-1.2.docx excel practice-1.2. excel practice-1.2.
YosefNigussie2
 
DOCX
excel practice-1.3.docx excel practice-1.3 excel practice-1.3
YosefNigussie2
 
DOCX
excel practice-1.4.docx excel practice-1.4
YosefNigussie2
 
PDF
maintain-equipment-and-consumubles maintain-equipment-and-consumubles.pdf
YosefNigussie2
 
PPTX
Introduction to Python Chapter 1-Introduction to Python.pptx Chapter 1-Introd...
YosefNigussie2
 
DOCX
excel practice-1.3.docx,excel practice-1.3
YosefNigussie2
 
DOCX
excel practice-1.2.docx,excel practice-1.1
YosefNigussie2
 
DOCX
excel practice-1.1.docx,excel practice-1.1
YosefNigussie2
 
DOCX
excel practice-1.0.docx,excel practice-1.0
YosefNigussie2
 
DOCX
excel practice,excel practice.docx,excel practice.docx.docx
YosefNigussie2
 
PPTX
Web Development Level-IIUSE INTERNET.pptx
YosefNigussie2
 
Chapter 4-database backup and recoveryProgramming Functions.pptx
YosefNigussie2
 
OSS1 OSS1 OSS1 OSS1 OSS1 OSS1 OSS1 OSS1.pptx
YosefNigussie2
 
excel practice-0.0.docx excel practice-0.0.
YosefNigussie2
 
excel practice-0.0.docx excel practice-0.0. excel practice-0.0.
YosefNigussie2
 
excel practice-1.0.docx excel practice-1.1. excel practice-1.1.
YosefNigussie2
 
excel practice-1.2.docx excel practice-1.2. excel practice-1.2.
YosefNigussie2
 
excel practice-1.3.docx excel practice-1.3 excel practice-1.3
YosefNigussie2
 
excel practice-1.4.docx excel practice-1.4
YosefNigussie2
 
maintain-equipment-and-consumubles maintain-equipment-and-consumubles.pdf
YosefNigussie2
 
Introduction to Python Chapter 1-Introduction to Python.pptx Chapter 1-Introd...
YosefNigussie2
 
excel practice-1.3.docx,excel practice-1.3
YosefNigussie2
 
excel practice-1.2.docx,excel practice-1.1
YosefNigussie2
 
excel practice-1.1.docx,excel practice-1.1
YosefNigussie2
 
excel practice-1.0.docx,excel practice-1.0
YosefNigussie2
 
excel practice,excel practice.docx,excel practice.docx.docx
YosefNigussie2
 
Web Development Level-IIUSE INTERNET.pptx
YosefNigussie2
 
Ad

Recently uploaded (20)

PPTX
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
pcprocore
 
PDF
Database Benchmarking for Performance Masterclass: Session 1 - Benchmarking F...
ScyllaDB
 
PDF
5 Things to Consider When Deploying AI in Your Enterprise
Safe Software
 
PDF
UiPath Agentic AI ile Akıllı Otomasyonun Yeni Çağı
UiPathCommunity
 
PDF
Java 25 and Beyond - A Roadmap of Innovations
Ana-Maria Mihalceanu
 
PPSX
Usergroup - OutSystems Architecture.ppsx
Kurt Vandevelde
 
PPTX
Curietech AI in action - Accelerate MuleSoft development
shyamraj55
 
PDF
Quantum AI Discoveries: Fractal Patterns Consciousness and Cyclical Universes
Saikat Basu
 
PDF
EIS-Webinar-Engineering-Retail-Infrastructure-06-16-2025.pdf
Earley Information Science
 
PDF
Optimizing the trajectory of a wheel loader working in short loading cycles
Reno Filla
 
PDF
LLM Search Readiness Audit - Dentsu x SEO Square - June 2025.pdf
Nick Samuel
 
PDF
The Future of Product Management in AI ERA.pdf
Alyona Owens
 
PDF
From Chatbot to Destroyer of Endpoints - Can ChatGPT Automate EDR Bypasses (1...
Priyanka Aash
 
PDF
Hyderabad MuleSoft In-Person Meetup (June 21, 2025) Slides
Ravi Tamada
 
PDF
Open Source Milvus Vector Database v 2.6
Zilliz
 
PDF
Enhancing Environmental Monitoring with Real-Time Data Integration: Leveragin...
Safe Software
 
PPTX
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Poster...
Michele Kryston
 
PPTX
Paycifi - Programmable Trust_Breakfast_PPTXT
FinTech Belgium
 
PDF
My Journey from CAD to BIM: A True Underdog Story
Safe Software
 
PPTX
Practical Applications of AI in Local Government
OnBoard
 
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
pcprocore
 
Database Benchmarking for Performance Masterclass: Session 1 - Benchmarking F...
ScyllaDB
 
5 Things to Consider When Deploying AI in Your Enterprise
Safe Software
 
UiPath Agentic AI ile Akıllı Otomasyonun Yeni Çağı
UiPathCommunity
 
Java 25 and Beyond - A Roadmap of Innovations
Ana-Maria Mihalceanu
 
Usergroup - OutSystems Architecture.ppsx
Kurt Vandevelde
 
Curietech AI in action - Accelerate MuleSoft development
shyamraj55
 
Quantum AI Discoveries: Fractal Patterns Consciousness and Cyclical Universes
Saikat Basu
 
EIS-Webinar-Engineering-Retail-Infrastructure-06-16-2025.pdf
Earley Information Science
 
Optimizing the trajectory of a wheel loader working in short loading cycles
Reno Filla
 
LLM Search Readiness Audit - Dentsu x SEO Square - June 2025.pdf
Nick Samuel
 
The Future of Product Management in AI ERA.pdf
Alyona Owens
 
From Chatbot to Destroyer of Endpoints - Can ChatGPT Automate EDR Bypasses (1...
Priyanka Aash
 
Hyderabad MuleSoft In-Person Meetup (June 21, 2025) Slides
Ravi Tamada
 
Open Source Milvus Vector Database v 2.6
Zilliz
 
Enhancing Environmental Monitoring with Real-Time Data Integration: Leveragin...
Safe Software
 
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Poster...
Michele Kryston
 
Paycifi - Programmable Trust_Breakfast_PPTXT
FinTech Belgium
 
My Journey from CAD to BIM: A True Underdog Story
Safe Software
 
Practical Applications of AI in Local Government
OnBoard
 
Ad

Chapter 2-Programming Basics and Arrays.pptx Chapter 2-Programming Basics and Arrays.pptx

  • 4. Python Variables  Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in memory..  Python variables do not need explicit declaration to reserve memory space. The declaration happens automatically when you assign a value to a variable.  python allows you to assign a single value to several variables or multiple objects to multiple variables simultaneously. 4 a = b = c = 1 a,b,c = 1,2,"john"
  • 5. Data types  Python has five standard data types  Numbers  String  List  Tuple  Dictionary 5
  • 6. Python Numbers  Python supports four different numerical types:  int (signed integers)  long (long integers, they can also be represented in octal and hexadecimal)  float (floating point real values)  complex (complex numbers) 6 var1 = 1 var2 = 10 del var del var_a, var_b
  • 7. Python Strings  Strings in Python are identified as a contiguous set of characters represented in the quotation marks.  Python allows for either pairs of single or double quotes. Subsets of strings can be taken using the slice operator ([ ] and [:] ) with indexes starting at 0 in the beginning of the string and working their way from -1 at the end.  The plus (+) sign is the string concatenation operator and the asterisk (*) is the repetition operator. 7
  • 8. 8 Example User inputs:  Enter your name: John  Enter your age:25 Out put:  Welcome, John ! you are now 25 Write a program which accepts name and age input from user and print it?
  • 9. Python Operators  Assignment operators(=)  Arithmetic operators(+,*,/,-)  Comparison operators(<,>,<=)  Logical operators(and, or, not)  Bitwise operators(^,&,|)  Data Type Conversions: Implicit or explicit 9
  • 10. 10 Arrays  An array is a data structure consisting of a collection of elements (values or variables), each identified by at least one array index or key  Arrays and Lists  Index Notation  Displaying Array Members  Multidimensional Arrays
  • 11. Python Lists  The most basic data structure in Python is the sequence. Each element of a sequence is assigned a number - its position or index. The first index is zero, the second index is one, and so forth.  The list is a most versatile datatype available in Python which can be written as a list of comma-separated values (items) between square brackets. Important thing about a list is that items in a list need not be of the same type.  Lists are mutable objects that can change their values 11 list1 = ['physics', 'chemistry', 1997, 2000]; list2 = [1, 2, 3, 4, 5 ]; list3 = ["a", "b", "c", "d"]
  • 12. Python Lists  Accessing Values in Lists: use the square brackets for slicing along with the index or indices to obtain value available at that index.  Updating Lists: You can update single or multiple elements of lists by giving the slice on the left-hand side of the assignment operator, and you can add to elements in a list with the append() method. 12
  • 13. Python Lists  Delete List Elements: To remove a list element, you can use either the del statement if you know exactly which element(s) you are deleting or the remove() method if you do not know.  Basic List Operations: Lists respond to the + and * operators much like strings; they mean concatenation and repetition here too, except that the result is a new list, not a string. 13
  • 14. Python Lists  Common List functions 14
  • 15. Python Lists  Common list methods 15
  • 16. Tuples  A tuple is a collection of objects which ordered and immutable.  The differences between tuples and lists are, the tuples cannot be changed unlike lists and tuples use parentheses, whereas lists use square brackets. 16 tup1 = ('physics', 'chemistry', 1997, 2000); tup2 = (1, 2, 3, 4, 5 ); tup3 = "a", "b", "c", "d";
  • 17. Tuples  Accessing Values in Tuples  Updating Tuples  Delete Tuple Elements  Basic Tuples Operations: Tuples respond to the + and * operators much like strings; they mean concatenation and repetition here too, except that the result is a new tuple, not a string. 17
  • 19. Dictionaries  Each key is separated from its value by a colon (:), the items are separated by commas, and the whole thing is enclosed in curly braces.  Keys are unique within a dictionary while values may not be. The values of a dictionary can be of any type, but the keys must be of an immutable data type such as strings, numbers, or tuples. 19
  • 20. Dictionaries  Accessing Values in Dictionary  Updating Dictionary  Delete Dictionary Elements 20
  • 21. Dictionaries  Properties of Dictionary Keys  More than one entry per key not allowed. Which means no duplicate key is allowed.  Keys must be immutable. 21 dict = {'Name': 'Zara', 'Age': 7, 'Name': 'Manni'} print "dict['Name']: ", dict['Name'] dict = {['Name']: 'Zara', 'Age': 7} print "dict['Name']: ", dict['Name']
  • 22. Dictionaries  Built-in Dictionary Functions & Methods 22

Editor's Notes

  • #9: Arithmetic :Addition, Subtraction, division, multiplication, module, floor division Assignment: =,+=,-+ and others Comparison: strict greater and lessor, greater/less than or equal, equal or not equal Logical: and, or and Not Bitwise: or , and, xor