SlideShare a Scribd company logo
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

Lists_tuples.pptx
Lists_tuples.pptxLists_tuples.pptx
Lists_tuples.pptx
M Vishnuvardhan Reddy
 
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
 
Chap10
Chap10Chap10
Chap10
Terry Yoast
 
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
 
List in Python
List in PythonList in Python
List in Python
Siddique Ibrahim
 
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
REXGAMING6
 
easyPy-Basic.pdf
easyPy-Basic.pdfeasyPy-Basic.pdf
easyPy-Basic.pdf
Mina Firoozgohar
 
16-sorting.ppt
16-sorting.ppt16-sorting.ppt
16-sorting.ppt
18Gunaalanpg
 
COLLECTIONS.pptx
COLLECTIONS.pptxCOLLECTIONS.pptx
COLLECTIONS.pptx
SruthyPJ
 
Python list
Python listPython list
Groovy
GroovyGroovy
Groovy
Vijay Shukla
 
Python-Ukllllllllllllllllllllllllllllnit 2.pdklllllllf
Python-Ukllllllllllllllllllllllllllllnit 2.pdklllllllfPython-Ukllllllllllllllllllllllllllllnit 2.pdklllllllf
Python-Ukllllllllllllllllllllllllllllnit 2.pdklllllllf
Meha46
 
Data Structure
Data StructureData Structure
Data Structure
HarshGupta663
 
Python revision tour II
Python revision tour IIPython revision tour II
Python revision tour II
Mr. Vikram Singh Slathia
 
MODULE-2.pptx
MODULE-2.pptxMODULE-2.pptx
MODULE-2.pptx
ASRPANDEY
 
Python lists &amp; sets
Python lists &amp; setsPython lists &amp; sets
Python lists &amp; sets
Aswini Dharmaraj
 
Data type list_methods_in_python
Data type list_methods_in_pythonData type list_methods_in_python
Data type list_methods_in_python
deepalishinkar1
 
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
AmuthachenthiruK
 
Python data handling notes
Python data handling notesPython data handling notes
Python data handling notes
Prof. Dr. K. Adisesha
 

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

A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
James Anderson
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
DianaGray10
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
SOFTTECHHUB
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
Kumud Singh
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
Edge AI and Vision Alliance
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AIEnchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Vladimir Iglovikov, Ph.D.
 
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
Zilliz
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
Daiki Mogmet Ito
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
Matthew Sinclair
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems S.M.S.A.
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 

Recently uploaded (20)

A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
 
UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6UiPath Test Automation using UiPath Test Suite series, part 6
UiPath Test Automation using UiPath Test Suite series, part 6
 
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
Goodbye Windows 11: Make Way for Nitrux Linux 3.5.0!
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
Mind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AIMind map of terminologies used in context of Generative AI
Mind map of terminologies used in context of Generative AI
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AIEnchancing adoption of Open Source Libraries. A case study on Albumentations.AI
Enchancing adoption of Open Source Libraries. A case study on Albumentations.AI
 
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
Introducing Milvus Lite: Easy-to-Install, Easy-to-Use vector database for you...
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
 
20240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 202420240609 QFM020 Irresponsible AI Reading List May 2024
20240609 QFM020 Irresponsible AI Reading List May 2024
 
Uni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdfUni Systems Copilot event_05062024_C.Vlachos.pdf
Uni Systems Copilot event_05062024_C.Vlachos.pdf
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 

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