SlideShare a Scribd company logo
1 of 29
welcome to
vibrant technologies and
computers
Vibrant Technology & Computers
“Best training Course in Mumbai”
www.vibranttechnologies.co.in
1
www.vibranttechnologies.co.in
2
type in which the values are made
up of elements that are themselves
values.
www.vibranttechnologies.co.in
3
Strings – Enclosed in Quotes, holds characters,
(immutable):
“This is a String”
Tuples – Values separated by commas, (usually
enclosed by parenthesis) and can hold any data
type (immutable):
(4 , True, “Test”, 34.8)
Lists – Enclosed in square brackets, separated
by commas, holds any data type (mutable):
[4, True, “Test”, 34.8]
Dictionaries – Enclosed in curly brackets,
elements separated by commas, key : value pairs
separated by colons, keys can be any immutable
data type, values can be any data type:
{ 1 : “I”, 2 : ”II”, 3 : “III”, 4 : “IV”, 5 : “V” }
Immutable Types
www.vibranttechnologies.co.in
4
Strings and Tuples are immutable, which
means that once you create them, you can
not change them.
The assignment operator (=) can make a
variable point to strings or tuples just like
simple data types:
myString = “This is a test”
myTuple = (1,45.8, True, “String Cheese”)
Strings & Tuples are both se q ue nce s , which
mean that they consist of an ordered set of
elements, with each element identified by an
index.
Accessing Elements
www.vibranttechnologies.co.in
5  myString = “This is a test.”
You can access a specific element using an
integer inde x which counts from the front of the
sequence (starting at ZERO!)
myString[0] produces 'T'
myString[1] produces 'h'
myString[2] produces 'i'
myString[3] produces 's'
The len() function can be used to find the
length of a sequence. Remember, the last
element is the length minus 1, because counting
starts at zero!
myString[ len(myString) – 1] produces
'.'
Counting Backwards
www.vibranttechnologies.co.in
6
 myString = “This is a test.”
As a short cut (to avoid writing
len(myString) ) you can simply count from
the end of the string using negative numbers:
myString[ len(myString) – 1 ]
produces '.'
myString[-1] also produces
'.'
myString[-2] produces
't'
myString[-3] produces
's'
myString[-4] produces
Index out of Range!
www.vibranttechnologies.co.in
7
 myString = “This is a test.”
Warning! If you try to access an element that
does not exist, Python will throw an error!
myString[5000] produces An ERROR!
myString[-100] produces An ERROR!
Traversals
www.vibranttechnologies.co.in
8
Many times you need to do something to
every element in a sequence. (e.g. Check
each letter in a string to see if it contains a
specific character.)
Doing something to every element in a
sequence is so common that it has a name: a
Traversal.
You can do a traversal using a while loop as
follows:
index = 0
while ( index < len (myString) ):
if myString[index] == 'J':
print “Found a J!”
index = index + 1
Easy Traversals – The FOR Loop
www.vibranttechnologies.co.in
9
Python makes traversals easy with a FOR loop:
for ELEMENT_VAR in SEQUENCE:
STATEMENT
STATEMENT
A for loop automatically assigns each element in
the sequence to the (programmer named)
ELEMENT_VAR, and then executes the
statements in the block of code following the for
loop once for each element.
Here is an example equivalent to the previous
WHILE loop:
for myVar in myString:
if myVar == 'J':
print “I found a J!”
Note that it takes care of the indexing variable for
us.
Grabbing Slices from a Sequence
www.vibranttechnologies.co.in
10
The slice operator will clip out part of a sequence.
It looks a lot like the bracket operator, but with a
colon that separates the “start” and “end” points.
SEQUENCE_VAR [ START : END ]
myString = “This is a test.”
myString[0:2] produces 'Th' (0, 1,
but NOT 2)
myString[3:6] produces 's i” (3-5, but
NOT 6)
POP QUIZ:
myString[ 1 : 4 ] produces ?
myString[ 5: 7 ] produces ?
Slices – Default values for
blanks
www.vibranttechnologies.co.in
11
 SEQUENCE_VAR [ START : END ]
 myString = “This is a test.”
If you leave the “start” part blank, it assumes
you want zero.
myString[ : 2] produces 'Th' (0,1, but
NOT 2)
myString[ : 6] produces 'This i' (0-5, but
NOT 6)
If you leave the “end” blank, it assumes you
want until the end of the string
myString[ 5 : ] produces 'is a test.' (5
Using Slices to make clones
(copies)
www.vibranttechnologies.co.in
12
You can assign a slice from a sequence to a
variable.
The variable points at a copy of the data.
myString = “This is a test.”
hisString = myString [ 1 : 4 ]
isString = myString [ 5 : 7 ]
testString = myString [10 : ]
Tuples
www.vibranttechnologies.co.in
13
Tuples can hold any type of data!
You can make one by separating some values
with comas. Convention says that we enclose
them with parenthesis to make the beginning
and end of the tuple explicit, as follows:
(4, True, “Test”, 14.8)
NOTE: Parenthesis are being overloaded
here, which make the commas very important!
(4) is NOT a tuple (it's a 4 in parenthesis)
(4,) IS a tuple of length 1 (note the trailing
comma)
Tuples are good when you want to group a
few variables together (firstName, lastName)
Using Tuples to return multiple
pieces of data!
www.vibranttechnologies.co.in
14
Tuples can also allow you to return multiple
pieces of data from a function:
def
area_volume_of_cube( sideLength):
area = 6 * sideLength *
sideLength
volume = sideLength * sideLength
* sideLength
return area, volume
myArea, myVolume =
area_volume_of_cube( 6 )
Tuples are sequences!
www.vibranttechnologies.co.in
15
Because tuples are sequences, we can
access them using the bracket operator just
like strings.
myTuple = ( 4,48.8,True, “Test”)
myTuple[0 ] produces 4
myTuple[ 1 ] produces 48.8
myTuple[ 2 ] produces True
myTuple[ -1 ] produces 'Test'
“Changing” Immutable data
types
www.vibranttechnologies.co.in
16
Immutable data types can not be changed
after they are created. Examples include
Strings and Tuples.
Although you can not change an immutable
data type, you can create a new variable that
has the changes you want to make.
For example, to capitalize the first letter in this
string:
myString = “all lowercase.”
myNewString = “A” + myString[1:]
We have concatenated two strings (a string
Changing mutable data types
www.vibranttechnologies.co.in
17
Mutable data types can be changed after
they are created. Examples include Lists and
Dictionaries.
These changes happen “in place”.
myList = ['l', 'o', 'w', 'e', 'r', 'c', 'a', 's',
'e']
myList[0] = 'L'
print myList produces:
[ 'L', 'o', 'w', 'e', 'r', 'c',
'a', 's', 'e']
Note that we are using the indexing operator
[brackets] in the same way that we always
Lists – like strings & tuples, but
mutable!
www.vibranttechnologies.co.in
18
Lists are a mutable data type that you can
create by enclosing a series of elements in
square brackets separated by commas. The
elements do not have to be of the same data
type:
myList = [ 23, True, 'Cheese”,
3.1459 ]
Unlike Strings and tuples, individual elements
in a list can be modified using the assignment
operator. After the following commands:
myList[0] = True
myList[1] = 24
Different Elements, Different
Types
www.vibranttechnologies.co.in
19
Unlike strings, which contain nothing but
letters, list elements can be of any data
type.
myList = [ True, 24, 'Cheese',
'Boo' ]
for eachElement in myList:
print type(eachElement)
produces:
<type 'bool'>
<type 'int'>
List Restrictions and the
append method
www.vibranttechnologies.co.in
20
Just like a string, you can't access an element
that doesn't exist. You also can not assign a
value to an element that doesn't exist.
Lists do have some helper methods. Perhaps
the most useful is the append method, which
adds a new value to the end of the list:
myList = [ True, 'Boo', 3]
myList.append(5)
print myList
[ True, 'Boo', 3, 5]
And now, for something
completely different!
www.vibranttechnologies.co.in
21
Dictionaries are an asso ciative data type.
Unlike sequences, they can use ANY
immutable data type as an index.
Dictionaries will associate a key (any
immutable data), with a value (any data).
For example, we can use a dictionary to
associate integer keys (the numbers 1-5) with
strings (their Roman numeral representation)
like this:
arabic2roman = { 1 : “I”, 2 :
”II”, 3 : “III”, 4 : “IV”, 5 : “V”
}
Dictionary example: Accessing
www.vibranttechnologies.co.in
22
 arabic2roman = { 1 : “I”, 2 :
”II”, 3 : “III”, 4 : “IV”, 5 : “V”
}
You can retrieve a value from a dictionary by
indexing with the associated key:
arabic2roman[1] produces 'I'
arabic2roman[5] produces 'V'
arabic2roman[4] produces 'IV'
Reassigning & Creating new
Key/Value associations
www.vibranttechnologies.co.in
23
 arabic2roman = { 1 : “I”, 2 :
”II”, 3 : “III”, 4 : “IV”, 5 : “V”
}
You can assign new values to existing keys:
arabic2roman [1] = 'one'
now:
arabic2roman[1] produces 'one'
You can create new key/value pairs:
arabic2roman[10] = 'X'
now
arabic2roman[10] produces 'X'
Dictionaries and default values with
the get method
www.vibranttechnologies.co.in
24
If you use an index that does not exist in a
dictionary, it will raise an exception (ERROR!)
But, you can use the get( INDEX, DEFAULT)
method to return a default value if the index
does not exist. For example:
arabic2roman.get(1,”None”)
produces 'I'
arabic2roman.get(5, “None”)
produces 'V'
arabic2roman.get(500, “None”)
produces 'None'
arabic2roman.get(“test”, “None”)
produces 'None'
Difference Between Aliases &
Clones
www.vibranttechnologies.co.in
25
More than one variable can point to the same
data. This is called an Alias.
For example:
a = [ 5, 10, 50, 100]
b = a
Now, a and b both point to the same list.
If you make a change to the data that a points to,
you are also changing the data that b points to:
a[0] = 'Changed'
a points to the list: [“Changed”, 10, 50, 100]
But because b points to the same data, b also
points to the list ['Changed', 10, 50, 100]
Cloning Data with the Slice
operator
www.vibranttechnologies.co.in
26
If you want to make a clone (copy) of a
sequence, you can use the slice operator
( [:] )
For example:
a = [ 5, 10, 50, 100]
b = a[0:2]
Now, b points to a cloned slice of a that is [ 5,
10]
If you make a change to the data that a points
to, you do NOT change the slice that b points
to.
a[0] = 'Changed'
a points to the list: [“Changed”, 10, 50, 100]
b still points to the (different) list [5, 10]
Cloning an entire list
www.vibranttechnologies.co.in
27
You can use the slice operator with a default
START and END to clone an entire list (make a
copy of it)
For example:
a = [ 5, 10, 50, 100]
b = a[: ]
Now, a and b point to different copies of the list
with the same data values.
If you make a change to the data that a points to,
nothing happens the the list that b points to.
a[0] = 'Changed'
a points to the list: [“Changed”, 10, 50, 100]
b points to the the copy of the old a: [ 5, 10, 50,
100]
Be very careful!
www.vibranttechnologies.co.in
28
The only difference in the above examples
was the use of the slice operator in addition to
the assignment operator:
b = a
vs
b = a[:]
This is a small difference in syntax, but it has
a very big semantic meaning!
Without the slice operator, a and b point to the
same list. Changes to one affect the other.
With it, they point to different copies of the list
that can be changed independently.
www.vibranttechnologies.co.in
29
Thankyou

More Related Content

What's hot

What's hot (18)

Basics of Python
Basics of PythonBasics of Python
Basics of Python
 
Python Traning presentation
Python Traning presentationPython Traning presentation
Python Traning presentation
 
Strings Arrays
Strings ArraysStrings Arrays
Strings Arrays
 
13. Java text processing
13.  Java text processing13.  Java text processing
13. Java text processing
 
Java Foundations: Lists, ArrayList<T>
Java Foundations: Lists, ArrayList<T>Java Foundations: Lists, ArrayList<T>
Java Foundations: Lists, ArrayList<T>
 
Python for Beginners(v2)
Python for Beginners(v2)Python for Beginners(v2)
Python for Beginners(v2)
 
Python for Data Science
Python for Data SciencePython for Data Science
Python for Data Science
 
Python language data types
Python language data typesPython language data types
Python language data types
 
Datastructures in python
Datastructures in pythonDatastructures in python
Datastructures in python
 
Introduction to python programming
Introduction to python programmingIntroduction to python programming
Introduction to python programming
 
Introduction to python programming 1
Introduction to python programming   1Introduction to python programming   1
Introduction to python programming 1
 
Introduction to python programming 2
Introduction to python programming   2Introduction to python programming   2
Introduction to python programming 2
 
Python programming : Strings
Python programming : StringsPython programming : Strings
Python programming : Strings
 
Java Foundations: Arrays
Java Foundations: ArraysJava Foundations: Arrays
Java Foundations: Arrays
 
Python Cheat Sheet
Python Cheat SheetPython Cheat Sheet
Python Cheat Sheet
 
Introduction to Python Language and Data Types
Introduction to Python Language and Data TypesIntroduction to Python Language and Data Types
Introduction to Python Language and Data Types
 
Oop lecture7
Oop lecture7Oop lecture7
Oop lecture7
 
Csharp4 arrays and_tuples
Csharp4 arrays and_tuplesCsharp4 arrays and_tuples
Csharp4 arrays and_tuples
 

Viewers also liked

Introduction to drupal course in-mumbai
Introduction to drupal course in-mumbaiIntroduction to drupal course in-mumbai
Introduction to drupal course in-mumbaivibrantuser
 
Introduction to drupal course in-mumbai
Introduction to drupal course in-mumbaiIntroduction to drupal course in-mumbai
Introduction to drupal course in-mumbaivibrantuser
 
Intro to wordpress 2
Intro to wordpress 2Intro to wordpress 2
Intro to wordpress 2vibrantuser
 
Introduction To WordPress
Introduction To WordPressIntroduction To WordPress
Introduction To WordPressCraig Bailey
 
Basic Wordpress PPT
Basic Wordpress PPT Basic Wordpress PPT
Basic Wordpress PPT mayur akabari
 
Best training-in-mumbai-shell scripting
Best training-in-mumbai-shell scriptingBest training-in-mumbai-shell scripting
Best training-in-mumbai-shell scriptingvibrantuser
 

Viewers also liked (7)

Introduction to drupal course in-mumbai
Introduction to drupal course in-mumbaiIntroduction to drupal course in-mumbai
Introduction to drupal course in-mumbai
 
Introduction to drupal course in-mumbai
Introduction to drupal course in-mumbaiIntroduction to drupal course in-mumbai
Introduction to drupal course in-mumbai
 
Intro to wordpress 2
Intro to wordpress 2Intro to wordpress 2
Intro to wordpress 2
 
Introduction To WordPress
Introduction To WordPressIntroduction To WordPress
Introduction To WordPress
 
Basic Wordpress PPT
Basic Wordpress PPT Basic Wordpress PPT
Basic Wordpress PPT
 
Best training-in-mumbai-shell scripting
Best training-in-mumbai-shell scriptingBest training-in-mumbai-shell scripting
Best training-in-mumbai-shell scripting
 
Slideshare ppt
Slideshare pptSlideshare ppt
Slideshare ppt
 

Similar to Python review2

RANDOMISATION-NUMERICAL METHODS FOR ENGINEERING.pptx
RANDOMISATION-NUMERICAL METHODS  FOR ENGINEERING.pptxRANDOMISATION-NUMERICAL METHODS  FOR ENGINEERING.pptx
RANDOMISATION-NUMERICAL METHODS FOR ENGINEERING.pptxOut Cast
 
Beginner's Python Cheat Sheet.pdf
Beginner's Python Cheat Sheet.pdfBeginner's Python Cheat Sheet.pdf
Beginner's Python Cheat Sheet.pdfAkhileshKumar436707
 
Visual Programing basic lectures 7.pptx
Visual Programing basic lectures  7.pptxVisual Programing basic lectures  7.pptx
Visual Programing basic lectures 7.pptxMrhaider4
 
Chapter 7.1
Chapter 7.1Chapter 7.1
Chapter 7.1sotlsoc
 
Data Type In Python.pptx
Data Type In Python.pptxData Type In Python.pptx
Data Type In Python.pptxhothyfa
 
Getting StartedCreate a class called Lab8. Use the same setup for .pdf
Getting StartedCreate a class called Lab8. Use the same setup for .pdfGetting StartedCreate a class called Lab8. Use the same setup for .pdf
Getting StartedCreate a class called Lab8. Use the same setup for .pdfinfo309708
 
Arrays in programming
Arrays in programmingArrays in programming
Arrays in programmingTaseerRao
 
23UCACC11 Python Programming (MTNC) (BCA)
23UCACC11 Python Programming (MTNC) (BCA)23UCACC11 Python Programming (MTNC) (BCA)
23UCACC11 Python Programming (MTNC) (BCA)ssuser7f90ae
 
Unit-2.Arrays and Strings.pptx.................
Unit-2.Arrays and Strings.pptx.................Unit-2.Arrays and Strings.pptx.................
Unit-2.Arrays and Strings.pptx.................suchitrapoojari984
 
python cheat sheat, Data science, Machine learning
python cheat sheat, Data science, Machine learningpython cheat sheat, Data science, Machine learning
python cheat sheat, Data science, Machine learningTURAGAVIJAYAAKASH
 
Beginner's Python Cheat Sheet
Beginner's Python Cheat SheetBeginner's Python Cheat Sheet
Beginner's Python Cheat SheetVerxus
 
beginners_python_cheat_sheet_pcc_all (1).pdf
beginners_python_cheat_sheet_pcc_all (1).pdfbeginners_python_cheat_sheet_pcc_all (1).pdf
beginners_python_cheat_sheet_pcc_all (1).pdfElNew2
 

Similar to Python review2 (20)

RANDOMISATION-NUMERICAL METHODS FOR ENGINEERING.pptx
RANDOMISATION-NUMERICAL METHODS  FOR ENGINEERING.pptxRANDOMISATION-NUMERICAL METHODS  FOR ENGINEERING.pptx
RANDOMISATION-NUMERICAL METHODS FOR ENGINEERING.pptx
 
Day2
Day2Day2
Day2
 
Beginner's Python Cheat Sheet.pdf
Beginner's Python Cheat Sheet.pdfBeginner's Python Cheat Sheet.pdf
Beginner's Python Cheat Sheet.pdf
 
Visual Programing basic lectures 7.pptx
Visual Programing basic lectures  7.pptxVisual Programing basic lectures  7.pptx
Visual Programing basic lectures 7.pptx
 
Chapter 3 Arrays in Java
Chapter 3 Arrays in JavaChapter 3 Arrays in Java
Chapter 3 Arrays in Java
 
Chapter 7.1
Chapter 7.1Chapter 7.1
Chapter 7.1
 
07+08slide.pptx
07+08slide.pptx07+08slide.pptx
07+08slide.pptx
 
Data Type In Python.pptx
Data Type In Python.pptxData Type In Python.pptx
Data Type In Python.pptx
 
Getting StartedCreate a class called Lab8. Use the same setup for .pdf
Getting StartedCreate a class called Lab8. Use the same setup for .pdfGetting StartedCreate a class called Lab8. Use the same setup for .pdf
Getting StartedCreate a class called Lab8. Use the same setup for .pdf
 
Arrays
ArraysArrays
Arrays
 
03. Week 03.pptx
03. Week 03.pptx03. Week 03.pptx
03. Week 03.pptx
 
Arrays in programming
Arrays in programmingArrays in programming
Arrays in programming
 
23UCACC11 Python Programming (MTNC) (BCA)
23UCACC11 Python Programming (MTNC) (BCA)23UCACC11 Python Programming (MTNC) (BCA)
23UCACC11 Python Programming (MTNC) (BCA)
 
Python-Cheat-Sheet.pdf
Python-Cheat-Sheet.pdfPython-Cheat-Sheet.pdf
Python-Cheat-Sheet.pdf
 
Python programming
Python  programmingPython  programming
Python programming
 
Unit-2.Arrays and Strings.pptx.................
Unit-2.Arrays and Strings.pptx.................Unit-2.Arrays and Strings.pptx.................
Unit-2.Arrays and Strings.pptx.................
 
2. Python Cheat Sheet.pdf
2. Python Cheat Sheet.pdf2. Python Cheat Sheet.pdf
2. Python Cheat Sheet.pdf
 
python cheat sheat, Data science, Machine learning
python cheat sheat, Data science, Machine learningpython cheat sheat, Data science, Machine learning
python cheat sheat, Data science, Machine learning
 
Beginner's Python Cheat Sheet
Beginner's Python Cheat SheetBeginner's Python Cheat Sheet
Beginner's Python Cheat Sheet
 
beginners_python_cheat_sheet_pcc_all (1).pdf
beginners_python_cheat_sheet_pcc_all (1).pdfbeginners_python_cheat_sheet_pcc_all (1).pdf
beginners_python_cheat_sheet_pcc_all (1).pdf
 

Recently uploaded

Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsPrecisely
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 

Recently uploaded (20)

Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power Systems
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 

Python review2

  • 1. welcome to vibrant technologies and computers Vibrant Technology & Computers “Best training Course in Mumbai” www.vibranttechnologies.co.in 1
  • 3. type in which the values are made up of elements that are themselves values. www.vibranttechnologies.co.in 3 Strings – Enclosed in Quotes, holds characters, (immutable): “This is a String” Tuples – Values separated by commas, (usually enclosed by parenthesis) and can hold any data type (immutable): (4 , True, “Test”, 34.8) Lists – Enclosed in square brackets, separated by commas, holds any data type (mutable): [4, True, “Test”, 34.8] Dictionaries – Enclosed in curly brackets, elements separated by commas, key : value pairs separated by colons, keys can be any immutable data type, values can be any data type: { 1 : “I”, 2 : ”II”, 3 : “III”, 4 : “IV”, 5 : “V” }
  • 4. Immutable Types www.vibranttechnologies.co.in 4 Strings and Tuples are immutable, which means that once you create them, you can not change them. The assignment operator (=) can make a variable point to strings or tuples just like simple data types: myString = “This is a test” myTuple = (1,45.8, True, “String Cheese”) Strings & Tuples are both se q ue nce s , which mean that they consist of an ordered set of elements, with each element identified by an index.
  • 5. Accessing Elements www.vibranttechnologies.co.in 5  myString = “This is a test.” You can access a specific element using an integer inde x which counts from the front of the sequence (starting at ZERO!) myString[0] produces 'T' myString[1] produces 'h' myString[2] produces 'i' myString[3] produces 's' The len() function can be used to find the length of a sequence. Remember, the last element is the length minus 1, because counting starts at zero! myString[ len(myString) – 1] produces '.'
  • 6. Counting Backwards www.vibranttechnologies.co.in 6  myString = “This is a test.” As a short cut (to avoid writing len(myString) ) you can simply count from the end of the string using negative numbers: myString[ len(myString) – 1 ] produces '.' myString[-1] also produces '.' myString[-2] produces 't' myString[-3] produces 's' myString[-4] produces
  • 7. Index out of Range! www.vibranttechnologies.co.in 7  myString = “This is a test.” Warning! If you try to access an element that does not exist, Python will throw an error! myString[5000] produces An ERROR! myString[-100] produces An ERROR!
  • 8. Traversals www.vibranttechnologies.co.in 8 Many times you need to do something to every element in a sequence. (e.g. Check each letter in a string to see if it contains a specific character.) Doing something to every element in a sequence is so common that it has a name: a Traversal. You can do a traversal using a while loop as follows: index = 0 while ( index < len (myString) ): if myString[index] == 'J': print “Found a J!” index = index + 1
  • 9. Easy Traversals – The FOR Loop www.vibranttechnologies.co.in 9 Python makes traversals easy with a FOR loop: for ELEMENT_VAR in SEQUENCE: STATEMENT STATEMENT A for loop automatically assigns each element in the sequence to the (programmer named) ELEMENT_VAR, and then executes the statements in the block of code following the for loop once for each element. Here is an example equivalent to the previous WHILE loop: for myVar in myString: if myVar == 'J': print “I found a J!” Note that it takes care of the indexing variable for us.
  • 10. Grabbing Slices from a Sequence www.vibranttechnologies.co.in 10 The slice operator will clip out part of a sequence. It looks a lot like the bracket operator, but with a colon that separates the “start” and “end” points. SEQUENCE_VAR [ START : END ] myString = “This is a test.” myString[0:2] produces 'Th' (0, 1, but NOT 2) myString[3:6] produces 's i” (3-5, but NOT 6) POP QUIZ: myString[ 1 : 4 ] produces ? myString[ 5: 7 ] produces ?
  • 11. Slices – Default values for blanks www.vibranttechnologies.co.in 11  SEQUENCE_VAR [ START : END ]  myString = “This is a test.” If you leave the “start” part blank, it assumes you want zero. myString[ : 2] produces 'Th' (0,1, but NOT 2) myString[ : 6] produces 'This i' (0-5, but NOT 6) If you leave the “end” blank, it assumes you want until the end of the string myString[ 5 : ] produces 'is a test.' (5
  • 12. Using Slices to make clones (copies) www.vibranttechnologies.co.in 12 You can assign a slice from a sequence to a variable. The variable points at a copy of the data. myString = “This is a test.” hisString = myString [ 1 : 4 ] isString = myString [ 5 : 7 ] testString = myString [10 : ]
  • 13. Tuples www.vibranttechnologies.co.in 13 Tuples can hold any type of data! You can make one by separating some values with comas. Convention says that we enclose them with parenthesis to make the beginning and end of the tuple explicit, as follows: (4, True, “Test”, 14.8) NOTE: Parenthesis are being overloaded here, which make the commas very important! (4) is NOT a tuple (it's a 4 in parenthesis) (4,) IS a tuple of length 1 (note the trailing comma) Tuples are good when you want to group a few variables together (firstName, lastName)
  • 14. Using Tuples to return multiple pieces of data! www.vibranttechnologies.co.in 14 Tuples can also allow you to return multiple pieces of data from a function: def area_volume_of_cube( sideLength): area = 6 * sideLength * sideLength volume = sideLength * sideLength * sideLength return area, volume myArea, myVolume = area_volume_of_cube( 6 )
  • 15. Tuples are sequences! www.vibranttechnologies.co.in 15 Because tuples are sequences, we can access them using the bracket operator just like strings. myTuple = ( 4,48.8,True, “Test”) myTuple[0 ] produces 4 myTuple[ 1 ] produces 48.8 myTuple[ 2 ] produces True myTuple[ -1 ] produces 'Test'
  • 16. “Changing” Immutable data types www.vibranttechnologies.co.in 16 Immutable data types can not be changed after they are created. Examples include Strings and Tuples. Although you can not change an immutable data type, you can create a new variable that has the changes you want to make. For example, to capitalize the first letter in this string: myString = “all lowercase.” myNewString = “A” + myString[1:] We have concatenated two strings (a string
  • 17. Changing mutable data types www.vibranttechnologies.co.in 17 Mutable data types can be changed after they are created. Examples include Lists and Dictionaries. These changes happen “in place”. myList = ['l', 'o', 'w', 'e', 'r', 'c', 'a', 's', 'e'] myList[0] = 'L' print myList produces: [ 'L', 'o', 'w', 'e', 'r', 'c', 'a', 's', 'e'] Note that we are using the indexing operator [brackets] in the same way that we always
  • 18. Lists – like strings & tuples, but mutable! www.vibranttechnologies.co.in 18 Lists are a mutable data type that you can create by enclosing a series of elements in square brackets separated by commas. The elements do not have to be of the same data type: myList = [ 23, True, 'Cheese”, 3.1459 ] Unlike Strings and tuples, individual elements in a list can be modified using the assignment operator. After the following commands: myList[0] = True myList[1] = 24
  • 19. Different Elements, Different Types www.vibranttechnologies.co.in 19 Unlike strings, which contain nothing but letters, list elements can be of any data type. myList = [ True, 24, 'Cheese', 'Boo' ] for eachElement in myList: print type(eachElement) produces: <type 'bool'> <type 'int'>
  • 20. List Restrictions and the append method www.vibranttechnologies.co.in 20 Just like a string, you can't access an element that doesn't exist. You also can not assign a value to an element that doesn't exist. Lists do have some helper methods. Perhaps the most useful is the append method, which adds a new value to the end of the list: myList = [ True, 'Boo', 3] myList.append(5) print myList [ True, 'Boo', 3, 5]
  • 21. And now, for something completely different! www.vibranttechnologies.co.in 21 Dictionaries are an asso ciative data type. Unlike sequences, they can use ANY immutable data type as an index. Dictionaries will associate a key (any immutable data), with a value (any data). For example, we can use a dictionary to associate integer keys (the numbers 1-5) with strings (their Roman numeral representation) like this: arabic2roman = { 1 : “I”, 2 : ”II”, 3 : “III”, 4 : “IV”, 5 : “V” }
  • 22. Dictionary example: Accessing www.vibranttechnologies.co.in 22  arabic2roman = { 1 : “I”, 2 : ”II”, 3 : “III”, 4 : “IV”, 5 : “V” } You can retrieve a value from a dictionary by indexing with the associated key: arabic2roman[1] produces 'I' arabic2roman[5] produces 'V' arabic2roman[4] produces 'IV'
  • 23. Reassigning & Creating new Key/Value associations www.vibranttechnologies.co.in 23  arabic2roman = { 1 : “I”, 2 : ”II”, 3 : “III”, 4 : “IV”, 5 : “V” } You can assign new values to existing keys: arabic2roman [1] = 'one' now: arabic2roman[1] produces 'one' You can create new key/value pairs: arabic2roman[10] = 'X' now arabic2roman[10] produces 'X'
  • 24. Dictionaries and default values with the get method www.vibranttechnologies.co.in 24 If you use an index that does not exist in a dictionary, it will raise an exception (ERROR!) But, you can use the get( INDEX, DEFAULT) method to return a default value if the index does not exist. For example: arabic2roman.get(1,”None”) produces 'I' arabic2roman.get(5, “None”) produces 'V' arabic2roman.get(500, “None”) produces 'None' arabic2roman.get(“test”, “None”) produces 'None'
  • 25. Difference Between Aliases & Clones www.vibranttechnologies.co.in 25 More than one variable can point to the same data. This is called an Alias. For example: a = [ 5, 10, 50, 100] b = a Now, a and b both point to the same list. If you make a change to the data that a points to, you are also changing the data that b points to: a[0] = 'Changed' a points to the list: [“Changed”, 10, 50, 100] But because b points to the same data, b also points to the list ['Changed', 10, 50, 100]
  • 26. Cloning Data with the Slice operator www.vibranttechnologies.co.in 26 If you want to make a clone (copy) of a sequence, you can use the slice operator ( [:] ) For example: a = [ 5, 10, 50, 100] b = a[0:2] Now, b points to a cloned slice of a that is [ 5, 10] If you make a change to the data that a points to, you do NOT change the slice that b points to. a[0] = 'Changed' a points to the list: [“Changed”, 10, 50, 100] b still points to the (different) list [5, 10]
  • 27. Cloning an entire list www.vibranttechnologies.co.in 27 You can use the slice operator with a default START and END to clone an entire list (make a copy of it) For example: a = [ 5, 10, 50, 100] b = a[: ] Now, a and b point to different copies of the list with the same data values. If you make a change to the data that a points to, nothing happens the the list that b points to. a[0] = 'Changed' a points to the list: [“Changed”, 10, 50, 100] b points to the the copy of the old a: [ 5, 10, 50, 100]
  • 28. Be very careful! www.vibranttechnologies.co.in 28 The only difference in the above examples was the use of the slice operator in addition to the assignment operator: b = a vs b = a[:] This is a small difference in syntax, but it has a very big semantic meaning! Without the slice operator, a and b point to the same list. Changes to one affect the other. With it, they point to different copies of the list that can be changed independently.