SlideShare a Scribd company logo
1 of 20
Download to read offline
Marina Hermaningsih
Introduction of
Python - 1
Whole numbers True or False
Decimal Numbers
Class = float
Slicing & Indexing are
not allowed
”Characters”
Integer Floating
Point
String
“ “
Boolean
Class = int
Slicing & Indexing are
not allowed
Class = bool
Slicing & Indexing are
not allowed
Class = str
Allow Slicing
& Indexing . Iterable
Data Type
Data Type
Class : list
Ordered, mutable,
iterable, allow duplicate,
indexing, slicing,
List [ ]
Tuple ( )
Class : tuple
Ordered, immutable,
iterable, allow duplicate,
indexing, slicing
Set { }
Class : set
Unordered, mutable,iterable
duplicate, indexing and slicing
are not allowed
Dictionary {key : value }
Class : dict
Keys are immutable, iterable
Indxing and slicing are not
allowed
[ ] { }
{ }
( )
Mutable
Mutable means we can
change the elements
/items after it has
been created
2023 Duplicate
Allow duplicate
means data can have
two items with the
same value
Ordered
Elements of data have a
defined order, that order
will not change after
running
Indexing
Positif index starts 0
from left side, while
negative index starts-1
from right index
Unordered
Elements of data don’t
have a defined order, that
order will change after
running
Slicing
Return sequence of
items/elements
Iterable = Can be iterated by loop method
Insight
Iterable
Python Operation
Comparison Mathematical Set
Arithmetic Assignment
x + y
x - y
x * y
x ** y
x / y
x // y
x % y
x > y
x < y
x >= y
x <= y
x == y
x != y
Union
x | y
Intersection
x & y
Difference
x – y != y – x
Symmetric Difference
x ^ y
x += y
x -= y
x *= y
x **= y
x /= y
x //= y
x %= y
Assignment operation can also be applied for mathematical set operation
Split Separate string and return it to list
Indexing and slicing the character of string
Notation
Count Count the occurrence of specified character
Concatenation Combine two or more strings with + operator
Len Count length of string character (include spaces)
Strip Remove spaces from left and right side of character
String Method
.append( )
Add new item to
the end of list
.remove( )
Delete specified
item of list
.sort()
Sort the list from
lowest to highest
number
.copy()
Copy all item of
list into new
variabel
.insert( )
Add new item at
specified index
List Method
.index() Search index of
specified item
.count() Count the number of
occurrence of
specified item
Tuple Method
1
2
Delete specified item
of set
Copy all item of set
into new variable
Add new item in set
Update items of set Delete all item of set
Set Method
.clear()
.copy()
.remove()
.update()
.add()
Remove key value pair
Access non existing key
1. Update value of an
existing key-value pair
2. Add new key-value pair
Dictionary Method
Notation []
.get()
del[] /
.pop()
You can check Python - Dictionary Methods (w3schools.com) for another Dictionary Method
If Statement Concept
If
1
Print
(‘’A’’)
True
False
Condition
A
If
If Else
2
Condition
A
If Elif
1
Print
(‘’A’’)
True
False
Condition
A
If
1st
Elif
Condition
B
Print
(‘’A’’)
True
Print
(‘’C’’)
False
Else
Print
(‘’A’’)
True
False
Condition
A
If
Print
(‘’B’’)
Else
H a y , e v e r y o n e !
0 1 2 3 4 5 6 7 8 9 10 11 12 13
-14 -13 -12 -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1
a = “Hay, everyone!”
1. Positive Index
In [ ] = a[0]
Out[ ] =‘H’
2. Negative Index
In [ ] = a[-1]
Out[ ] = ‘!’
3. Slicing with Starting and Ending Index
#Positive Index
In [ ] = a[0:3]
Out[ ] = ‘Hay’
#Negative Index
In [ ] = a[-14:-11]
Out[ ] = ‘Hay’
4. Slicing with Ending Index
#Positive Index
In [ ] = a[:3]
Out[ ] = ‘Hay’
#Negative Index
In [ ] = a[:-11]
Out[ ] = ‘Hay’
Example of Indexing and Slicing
5. Slicing with Starting Index
#Positive Index
In [ ] = a[5:]
Out[ ] = ‘everyone!’
#Negative Index
In [ ] = a[-9:]
Out[ ] = ‘everyone!’
6. Slicing with Step
#Positive Index
In [ ] = a[::2]
Out[ ] = ‘Hy vroe’
#Negative Index
In [ ] = a[::-2]
Out[ ] = ‘!nyee,a’
7. Slicing with Step, Starting and Ending Index
#Positive Index
In [ ] = a[0:13:2]
Out[ ] = ‘Hy vroe’
#Negative Index
In [ ] = a[-1:-14:-2]
Out[ ] = ‘’!nyee,a’
H a y , e v e r y o n e !
0 1 2 3 4 5 6 7 8 9 10 11 12 13
-14 -13 -12 -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1
a = “Hay, everyone!”
Example of Indexing and Slicing
Unpacking List
The sequence of element list will not change after running,
thus the list is ordered
When we use method “sort”, the sequence of element
list has changed
Variable Known : 1. Unpacking List without Index
You can unpack all
element of list
Or unpack
only some
element of
list
Unpacking List
Result is tuple
Use method “enumerate”
2. Unpacking List with Index
Result is not tuple
Unpacking Tuple
The sequence of element tuple will not change
after running, thus the tuple is ordered
When we use method “sort”, the sequence of element
tuple has not change. It means tuple is mutable
Variable Known :
Or unpack only
some element of
tuple
Unpacking Tuple
You can unpack all element of tuple
1. Unpacking Tuple without Index 2. Unpacking Tuple with Index
Result is not tuple
Result is tuple
The sequence of element set will change after running,
thus the list is unordered
Set does not support indexing. So when we unpacking set, the result is random order
Unpacking Set
Variable Known :
1. Unpacking with “items” Method
Result is key and value
Unpacking Dictionary
Dictionary consists of key (name, age) and value (Shela, 25)
Variable Known : 2. Unpacking with “keys” Method
Result is key
3. Unpacking with “values” Method
Result is values
THANK YOU!

More Related Content

Similar to Introduction of Python-1.pdf

11 Introduction to lists.pptx
11 Introduction to lists.pptx11 Introduction to lists.pptx
11 Introduction to lists.pptx
ssuser8e50d8
 
Python Unit 5 Questions n Notes.pdf
Python Unit 5 Questions n Notes.pdfPython Unit 5 Questions n Notes.pdf
Python Unit 5 Questions n Notes.pdf
MCCMOTOR
 
RANDOMISATION-NUMERICAL METHODS FOR ENGINEERING.pptx
RANDOMISATION-NUMERICAL METHODS  FOR ENGINEERING.pptxRANDOMISATION-NUMERICAL METHODS  FOR ENGINEERING.pptx
RANDOMISATION-NUMERICAL METHODS FOR ENGINEERING.pptx
Out Cast
 
COLLECTIONS.pptx
COLLECTIONS.pptxCOLLECTIONS.pptx
COLLECTIONS.pptx
SruthyPJ
 
Python-Ukllllllllllllllllllllllllllllnit 2.pdklllllllf
Python-Ukllllllllllllllllllllllllllllnit 2.pdklllllllfPython-Ukllllllllllllllllllllllllllllnit 2.pdklllllllf
Python-Ukllllllllllllllllllllllllllllnit 2.pdklllllllf
Meha46
 

Similar to Introduction of Python-1.pdf (20)

Lists_tuples.pptx
Lists_tuples.pptxLists_tuples.pptx
Lists_tuples.pptx
 
11 Introduction to lists.pptx
11 Introduction to lists.pptx11 Introduction to lists.pptx
11 Introduction to lists.pptx
 
Python Unit 5 Questions n Notes.pdf
Python Unit 5 Questions n Notes.pdfPython Unit 5 Questions n Notes.pdf
Python Unit 5 Questions n Notes.pdf
 
Chap10
Chap10Chap10
Chap10
 
RANDOMISATION-NUMERICAL METHODS FOR ENGINEERING.pptx
RANDOMISATION-NUMERICAL METHODS  FOR ENGINEERING.pptxRANDOMISATION-NUMERICAL METHODS  FOR ENGINEERING.pptx
RANDOMISATION-NUMERICAL METHODS FOR ENGINEERING.pptx
 
List in Python
List in PythonList in Python
List in Python
 
computer science tuple in python project.pdf
computer science tuple in python project.pdfcomputer science tuple in python project.pdf
computer science tuple in python project.pdf
 
easyPy-Basic.pdf
easyPy-Basic.pdfeasyPy-Basic.pdf
easyPy-Basic.pdf
 
16-sorting.ppt
16-sorting.ppt16-sorting.ppt
16-sorting.ppt
 
COLLECTIONS.pptx
COLLECTIONS.pptxCOLLECTIONS.pptx
COLLECTIONS.pptx
 
Python list
Python listPython list
Python list
 
Groovy
GroovyGroovy
Groovy
 
Python-Ukllllllllllllllllllllllllllllnit 2.pdklllllllf
Python-Ukllllllllllllllllllllllllllllnit 2.pdklllllllfPython-Ukllllllllllllllllllllllllllllnit 2.pdklllllllf
Python-Ukllllllllllllllllllllllllllllnit 2.pdklllllllf
 
Data Structure
Data StructureData Structure
Data Structure
 
Python revision tour II
Python revision tour IIPython revision tour II
Python revision tour II
 
MODULE-2.pptx
MODULE-2.pptxMODULE-2.pptx
MODULE-2.pptx
 
Python lists &amp; sets
Python lists &amp; setsPython lists &amp; sets
Python lists &amp; sets
 
Data type list_methods_in_python
Data type list_methods_in_pythonData type list_methods_in_python
Data type list_methods_in_python
 
AD3251-LINKED LIST,STACK ADT,QUEUE ADT.docx
AD3251-LINKED LIST,STACK ADT,QUEUE ADT.docxAD3251-LINKED LIST,STACK ADT,QUEUE ADT.docx
AD3251-LINKED LIST,STACK ADT,QUEUE ADT.docx
 
Python data handling notes
Python data handling notesPython data handling notes
Python data handling notes
 

Recently uploaded

CORS (Kitworks Team Study 양다윗 발표자료 240510)
CORS (Kitworks Team Study 양다윗 발표자료 240510)CORS (Kitworks Team Study 양다윗 발표자료 240510)
CORS (Kitworks Team Study 양다윗 발표자료 240510)
Wonjun Hwang
 
Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider  Progress from Awareness to Implementation.pptxTales from a Passkey Provider  Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
FIDO Alliance
 
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptxHarnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
FIDO Alliance
 
Microsoft BitLocker Bypass Attack Method.pdf
Microsoft BitLocker Bypass Attack Method.pdfMicrosoft BitLocker Bypass Attack Method.pdf
Microsoft BitLocker Bypass Attack Method.pdf
Overkill Security
 

Recently uploaded (20)

Introduction to FIDO Authentication and Passkeys.pptx
Introduction to FIDO Authentication and Passkeys.pptxIntroduction to FIDO Authentication and Passkeys.pptx
Introduction to FIDO Authentication and Passkeys.pptx
 
Working together SRE & Platform Engineering
Working together SRE & Platform EngineeringWorking together SRE & Platform Engineering
Working together SRE & Platform Engineering
 
الأمن السيبراني - ما لا يسع للمستخدم جهله
الأمن السيبراني - ما لا يسع للمستخدم جهلهالأمن السيبراني - ما لا يسع للمستخدم جهله
الأمن السيبراني - ما لا يسع للمستخدم جهله
 
2024 May Patch Tuesday
2024 May Patch Tuesday2024 May Patch Tuesday
2024 May Patch Tuesday
 
Continuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on ThanabotsContinuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
Continuing Bonds Through AI: A Hermeneutic Reflection on Thanabots
 
Intro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptxIntro to Passkeys and the State of Passwordless.pptx
Intro to Passkeys and the State of Passwordless.pptx
 
Navigating the Large Language Model choices_Ravi Daparthi
Navigating the Large Language Model choices_Ravi DaparthiNavigating the Large Language Model choices_Ravi Daparthi
Navigating the Large Language Model choices_Ravi Daparthi
 
How to Check GPS Location with a Live Tracker in Pakistan
How to Check GPS Location with a Live Tracker in PakistanHow to Check GPS Location with a Live Tracker in Pakistan
How to Check GPS Location with a Live Tracker in Pakistan
 
CORS (Kitworks Team Study 양다윗 발표자료 240510)
CORS (Kitworks Team Study 양다윗 발표자료 240510)CORS (Kitworks Team Study 양다윗 발표자료 240510)
CORS (Kitworks Team Study 양다윗 발표자료 240510)
 
Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider  Progress from Awareness to Implementation.pptxTales from a Passkey Provider  Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
 
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptxHarnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
Harnessing Passkeys in the Battle Against AI-Powered Cyber Threats.pptx
 
Microsoft BitLocker Bypass Attack Method.pdf
Microsoft BitLocker Bypass Attack Method.pdfMicrosoft BitLocker Bypass Attack Method.pdf
Microsoft BitLocker Bypass Attack Method.pdf
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDM
 
How to Check CNIC Information Online with Pakdata cf
How to Check CNIC Information Online with Pakdata cfHow to Check CNIC Information Online with Pakdata cf
How to Check CNIC Information Online with Pakdata cf
 
Cyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptx
Cyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptxCyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptx
Cyber Insurance - RalphGilot - Embry-Riddle Aeronautical University.pptx
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
 
Microsoft CSP Briefing Pre-Engagement - Questionnaire
Microsoft CSP Briefing Pre-Engagement - QuestionnaireMicrosoft CSP Briefing Pre-Engagement - Questionnaire
Microsoft CSP Briefing Pre-Engagement - Questionnaire
 
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
 
Top 10 CodeIgniter Development Companies
Top 10 CodeIgniter Development CompaniesTop 10 CodeIgniter Development Companies
Top 10 CodeIgniter Development Companies
 
AI mind or machine power point presentation
AI mind or machine power point presentationAI mind or machine power point presentation
AI mind or machine power point presentation
 

Introduction of Python-1.pdf

  • 2. Whole numbers True or False Decimal Numbers Class = float Slicing & Indexing are not allowed ”Characters” Integer Floating Point String “ “ Boolean Class = int Slicing & Indexing are not allowed Class = bool Slicing & Indexing are not allowed Class = str Allow Slicing & Indexing . Iterable Data Type
  • 3. Data Type Class : list Ordered, mutable, iterable, allow duplicate, indexing, slicing, List [ ] Tuple ( ) Class : tuple Ordered, immutable, iterable, allow duplicate, indexing, slicing Set { } Class : set Unordered, mutable,iterable duplicate, indexing and slicing are not allowed Dictionary {key : value } Class : dict Keys are immutable, iterable Indxing and slicing are not allowed [ ] { } { } ( )
  • 4. Mutable Mutable means we can change the elements /items after it has been created 2023 Duplicate Allow duplicate means data can have two items with the same value Ordered Elements of data have a defined order, that order will not change after running Indexing Positif index starts 0 from left side, while negative index starts-1 from right index Unordered Elements of data don’t have a defined order, that order will change after running Slicing Return sequence of items/elements Iterable = Can be iterated by loop method Insight Iterable
  • 5. Python Operation Comparison Mathematical Set Arithmetic Assignment x + y x - y x * y x ** y x / y x // y x % y x > y x < y x >= y x <= y x == y x != y Union x | y Intersection x & y Difference x – y != y – x Symmetric Difference x ^ y x += y x -= y x *= y x **= y x /= y x //= y x %= y Assignment operation can also be applied for mathematical set operation
  • 6. Split Separate string and return it to list Indexing and slicing the character of string Notation Count Count the occurrence of specified character Concatenation Combine two or more strings with + operator Len Count length of string character (include spaces) Strip Remove spaces from left and right side of character String Method
  • 7. .append( ) Add new item to the end of list .remove( ) Delete specified item of list .sort() Sort the list from lowest to highest number .copy() Copy all item of list into new variabel .insert( ) Add new item at specified index List Method
  • 8. .index() Search index of specified item .count() Count the number of occurrence of specified item Tuple Method 1 2
  • 9. Delete specified item of set Copy all item of set into new variable Add new item in set Update items of set Delete all item of set Set Method .clear() .copy() .remove() .update() .add()
  • 10. Remove key value pair Access non existing key 1. Update value of an existing key-value pair 2. Add new key-value pair Dictionary Method Notation [] .get() del[] / .pop() You can check Python - Dictionary Methods (w3schools.com) for another Dictionary Method
  • 11. If Statement Concept If 1 Print (‘’A’’) True False Condition A If If Else 2 Condition A If Elif 1 Print (‘’A’’) True False Condition A If 1st Elif Condition B Print (‘’A’’) True Print (‘’C’’) False Else Print (‘’A’’) True False Condition A If Print (‘’B’’) Else
  • 12. H a y , e v e r y o n e ! 0 1 2 3 4 5 6 7 8 9 10 11 12 13 -14 -13 -12 -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 a = “Hay, everyone!” 1. Positive Index In [ ] = a[0] Out[ ] =‘H’ 2. Negative Index In [ ] = a[-1] Out[ ] = ‘!’ 3. Slicing with Starting and Ending Index #Positive Index In [ ] = a[0:3] Out[ ] = ‘Hay’ #Negative Index In [ ] = a[-14:-11] Out[ ] = ‘Hay’ 4. Slicing with Ending Index #Positive Index In [ ] = a[:3] Out[ ] = ‘Hay’ #Negative Index In [ ] = a[:-11] Out[ ] = ‘Hay’ Example of Indexing and Slicing
  • 13. 5. Slicing with Starting Index #Positive Index In [ ] = a[5:] Out[ ] = ‘everyone!’ #Negative Index In [ ] = a[-9:] Out[ ] = ‘everyone!’ 6. Slicing with Step #Positive Index In [ ] = a[::2] Out[ ] = ‘Hy vroe’ #Negative Index In [ ] = a[::-2] Out[ ] = ‘!nyee,a’ 7. Slicing with Step, Starting and Ending Index #Positive Index In [ ] = a[0:13:2] Out[ ] = ‘Hy vroe’ #Negative Index In [ ] = a[-1:-14:-2] Out[ ] = ‘’!nyee,a’ H a y , e v e r y o n e ! 0 1 2 3 4 5 6 7 8 9 10 11 12 13 -14 -13 -12 -11 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 a = “Hay, everyone!” Example of Indexing and Slicing
  • 14. Unpacking List The sequence of element list will not change after running, thus the list is ordered When we use method “sort”, the sequence of element list has changed Variable Known : 1. Unpacking List without Index You can unpack all element of list Or unpack only some element of list
  • 15. Unpacking List Result is tuple Use method “enumerate” 2. Unpacking List with Index Result is not tuple
  • 16. Unpacking Tuple The sequence of element tuple will not change after running, thus the tuple is ordered When we use method “sort”, the sequence of element tuple has not change. It means tuple is mutable Variable Known :
  • 17. Or unpack only some element of tuple Unpacking Tuple You can unpack all element of tuple 1. Unpacking Tuple without Index 2. Unpacking Tuple with Index Result is not tuple Result is tuple
  • 18. The sequence of element set will change after running, thus the list is unordered Set does not support indexing. So when we unpacking set, the result is random order Unpacking Set Variable Known :
  • 19. 1. Unpacking with “items” Method Result is key and value Unpacking Dictionary Dictionary consists of key (name, age) and value (Shela, 25) Variable Known : 2. Unpacking with “keys” Method Result is key 3. Unpacking with “values” Method Result is values