SlideShare a Scribd company logo
1 of 16
Download to read offline
A Python Crash Course
Alex-P. Natsios – George Stoumpos
Technological Institute of Larissa
5 Dec 2012
Alex-P. Natsios – George Stoumpos Diving into Python
A few words about python
Characteristics:
created and published
by Guido Van Rossum in 1991
Interpreted
Multiplatform
Object Oriented
Dynamic Typing
Coding Style
Alex-P. Natsios – George Stoumpos Diving into Python
How to Start Python?
You can either run python from a script or Interactively:
Interactive:
(using the interpreter to run python code)
$ python
>>> print ”Hello there!”
Hello there
From a script:
(using a text file with python code)
$ python myscript.py
Hello there!
$
Alex-P. Natsios – George Stoumpos Diving into Python
Data types in Python
Numbers: Integer(42), float(13.37), complex(12+3n)
Strings: ”nothing interesting here move along”
Dictionaries: dict = {name : ‘Maria’, age : 22, 42 : ‘haha’ }
Lists: list = [1, ‘classic’, 2, ‘boring’]
Tuples: tuple = ( 1, 2, 42, ‘Maria’, (1,2,3) )
Objects: instance = Class(‘foobar’)
Modules: import antigravity
Alex-P. Natsios – George Stoumpos Diving into Python
Python has objects!
Everything in python is an object and every object has its
attributes.
Object Attributes:
>>> name = ‘maria’
>>> name.index(‘i’)
3
breaking down the above statement we have:
variable
delimeter
attribute
parameters (if any)
Alex-P. Natsios – George Stoumpos Diving into Python
Another peek in Attributes/Methods
Attributes?! Methods?! i can’t remember all these stuff!
Lucky you! you dont have to know all of them
using dir(): dir allows you to peek into an object and learn about its supported
methods
lets take a look at a list for example. >>> dir(list):
[‘append’, ‘extend’, ‘insert’, ‘remove’, ‘pop’, ‘index’, ‘count’, ‘sort’, ‘reverse’]
Alex-P. Natsios – George Stoumpos Diving into Python
Back to data type fun
Dictionaries
Example
>>> dict = {name : ‘Maria’, age : 22, 42 : ‘haha’ }
>>> dict[’age’]
22
>>> ‘name’ in dict
True
>>> del dict[’age’]
(we could also use pop to also return the removed key’s value)
Alex-P. Natsios – George Stoumpos Diving into Python
Back to data type fun
Lists
Example
>>> list = [1, ‘classic’, 2, ‘boring’]
>>> list.append(”Maria”)
>>> list
[1, ‘classic’, 2 ‘boring’, ‘Maria’]
>>> list.insert(4,”Alex”)
>>> list
[1, ‘classic’, 2 ‘boring’, ‘Alex’, ‘Maria’]
Alex-P. Natsios – George Stoumpos Diving into Python
Back to data type fun
Tuples
Tuples also known as Sequences and as such they are ordered.
you can also slice them using the slice operator:
Slice Operator
mysequence[ i : j ]
with ‘i’ and ‘j’ being your range in the sequence ( i = start , j = one past the end )
Example
tuple = ( 1, 2, 42, ‘Maria’, (1,2,3) )
>>> tuple[0]
1
>>> tuple[3]
‘Maria’
>>> tuple[1:2]
(1,42)
>>> tuple[-1]
(1,2,3)
>>> tuple[3:]
(‘Maria’,(1,2,3))
Alex-P. Natsios – George Stoumpos Diving into Python
Python type mutability
The value of some objects can change. Objects whose value can
change are said to be mutable;
objects whose value is unchangeable once they are created are
called immutable.
mutable
Dictionaries, Lists
immutable
Numbers, Strings, Tuples, Frozensets
Alex-P. Natsios – George Stoumpos Diving into Python
Flow Control
Conditionals
IF statement
name = ”Maria”
if name == ”Maria”:
print ”Hello Maria!”
elif name == ”George”:
print ”Hello George!”
else:
print ”Hello stranger!”
Alex-P. Natsios – George Stoumpos Diving into Python
Flow Control
Loops
While loop
i = 0
while i<5:
print i
i += 1
Alex-P. Natsios – George Stoumpos Diving into Python
Flow Control
Loops
for loop
for item in range(1,100):
print item
yet another for loop
names = (”Maria”, ”George”, ”Helen”, ”Alex”)
for item in names:
print item
Alex-P. Natsios – George Stoumpos Diving into Python
Numeric Operators
+ - * / Your everyday numeric operations.
% Modulus - Divides left hand operant by right hand operant.
Returns ‘Remainder’
** Exponent - performs exponential calculation on operant.
// Floor Division - division operant where the digits after the
result’s decimal point are removed.
Alex-P. Natsios – George Stoumpos Diving into Python
Function Definition
a simple function
>>> def foo(bar):
print bar
>>> foo(123)
123
Alex-P. Natsios – George Stoumpos Diving into Python
Class Definition
a simple class
class AddressBookEntry(object):
def init (self, name, phone):
self.name = name
self.phone = phone
def update phone(self, phone):
self.phone = phone
Alex-P. Natsios – George Stoumpos Diving into Python

More Related Content

What's hot

HaskellとDebianの辛くて甘い関係
HaskellとDebianの辛くて甘い関係HaskellとDebianの辛くて甘い関係
HaskellとDebianの辛くて甘い関係Kiwamu Okabe
 
Intro To Moose
Intro To MooseIntro To Moose
Intro To MoosecPanel
 
GeoMapper, Python Script for Visualizing Data on Social Networks with Geo-loc...
GeoMapper, Python Script for Visualizing Data on Social Networks with Geo-loc...GeoMapper, Python Script for Visualizing Data on Social Networks with Geo-loc...
GeoMapper, Python Script for Visualizing Data on Social Networks with Geo-loc...Marcel Caraciolo
 
Derping With Kotlin
Derping With KotlinDerping With Kotlin
Derping With KotlinRoss Tuck
 
SPL - The Undiscovered Library - PHPBarcelona 2015
SPL - The Undiscovered Library - PHPBarcelona 2015SPL - The Undiscovered Library - PHPBarcelona 2015
SPL - The Undiscovered Library - PHPBarcelona 2015Mark Baker
 
ECMAScript 6, o cómo usar el JavaScript del futuro hoy
ECMAScript 6, o cómo usar el JavaScript del futuro hoyECMAScript 6, o cómo usar el JavaScript del futuro hoy
ECMAScript 6, o cómo usar el JavaScript del futuro hoySoftware Guru
 
Haskell - Being lazy with class
Haskell - Being lazy with classHaskell - Being lazy with class
Haskell - Being lazy with classTiago Babo
 
Benchy: Lightweight framework for Performance Benchmarks
Benchy: Lightweight framework for Performance Benchmarks Benchy: Lightweight framework for Performance Benchmarks
Benchy: Lightweight framework for Performance Benchmarks Marcel Caraciolo
 
Laboratory activity 3 b3
Laboratory activity 3 b3Laboratory activity 3 b3
Laboratory activity 3 b3Jomel Penalba
 
Tree Top
Tree TopTree Top
Tree TopeventRT
 
Hands on Hadoop and pig
Hands on Hadoop and pigHands on Hadoop and pig
Hands on Hadoop and pigSudar Muthu
 
Practical pig
Practical pigPractical pig
Practical pigtrihug
 
Phishing for Root (How I Got Access to Root on Your Computer With 8 Seconds o...
Phishing for Root (How I Got Access to Root on Your Computer With 8 Seconds o...Phishing for Root (How I Got Access to Root on Your Computer With 8 Seconds o...
Phishing for Root (How I Got Access to Root on Your Computer With 8 Seconds o...Vi Grey
 

What's hot (15)

HaskellとDebianの辛くて甘い関係
HaskellとDebianの辛くて甘い関係HaskellとDebianの辛くて甘い関係
HaskellとDebianの辛くて甘い関係
 
Intro To Moose
Intro To MooseIntro To Moose
Intro To Moose
 
GeoMapper, Python Script for Visualizing Data on Social Networks with Geo-loc...
GeoMapper, Python Script for Visualizing Data on Social Networks with Geo-loc...GeoMapper, Python Script for Visualizing Data on Social Networks with Geo-loc...
GeoMapper, Python Script for Visualizing Data on Social Networks with Geo-loc...
 
Derping With Kotlin
Derping With KotlinDerping With Kotlin
Derping With Kotlin
 
Pg py-and-squid-pypgday
Pg py-and-squid-pypgdayPg py-and-squid-pypgday
Pg py-and-squid-pypgday
 
SPL - The Undiscovered Library - PHPBarcelona 2015
SPL - The Undiscovered Library - PHPBarcelona 2015SPL - The Undiscovered Library - PHPBarcelona 2015
SPL - The Undiscovered Library - PHPBarcelona 2015
 
OMG JavaScript
OMG JavaScriptOMG JavaScript
OMG JavaScript
 
ECMAScript 6, o cómo usar el JavaScript del futuro hoy
ECMAScript 6, o cómo usar el JavaScript del futuro hoyECMAScript 6, o cómo usar el JavaScript del futuro hoy
ECMAScript 6, o cómo usar el JavaScript del futuro hoy
 
Haskell - Being lazy with class
Haskell - Being lazy with classHaskell - Being lazy with class
Haskell - Being lazy with class
 
Benchy: Lightweight framework for Performance Benchmarks
Benchy: Lightweight framework for Performance Benchmarks Benchy: Lightweight framework for Performance Benchmarks
Benchy: Lightweight framework for Performance Benchmarks
 
Laboratory activity 3 b3
Laboratory activity 3 b3Laboratory activity 3 b3
Laboratory activity 3 b3
 
Tree Top
Tree TopTree Top
Tree Top
 
Hands on Hadoop and pig
Hands on Hadoop and pigHands on Hadoop and pig
Hands on Hadoop and pig
 
Practical pig
Practical pigPractical pig
Practical pig
 
Phishing for Root (How I Got Access to Root on Your Computer With 8 Seconds o...
Phishing for Root (How I Got Access to Root on Your Computer With 8 Seconds o...Phishing for Root (How I Got Access to Root on Your Computer With 8 Seconds o...
Phishing for Root (How I Got Access to Root on Your Computer With 8 Seconds o...
 

Viewers also liked

erwin dizon updated resume july 2016
erwin dizon updated resume july 2016erwin dizon updated resume july 2016
erwin dizon updated resume july 2016d. erwin vidanes
 
Tutoriel powerpoint
Tutoriel powerpointTutoriel powerpoint
Tutoriel powerpointsportsplanif
 
Year 6 lesson plan - digital information
Year 6 lesson plan - digital informationYear 6 lesson plan - digital information
Year 6 lesson plan - digital informationmr_mallard1995
 
An Act Amending Republic Act No. 9520
An Act Amending Republic Act No. 9520An Act Amending Republic Act No. 9520
An Act Amending Republic Act No. 9520jo bitonio
 
Coop First: how non-zero-sum games are reshaping our digital landscape
Coop First: how non-zero-sum games are reshaping our digital landscapeCoop First: how non-zero-sum games are reshaping our digital landscape
Coop First: how non-zero-sum games are reshaping our digital landscapeAmy Jo Kim
 
Community pharmacy
Community pharmacyCommunity pharmacy
Community pharmacyHazem Ashraf
 
NSCC Agri Tourism (1)
NSCC  Agri Tourism (1)NSCC  Agri Tourism (1)
NSCC Agri Tourism (1)jo bitonio
 
MediaRadar_WhitePaper_DigitalPolitical_FIN.PDF
MediaRadar_WhitePaper_DigitalPolitical_FIN.PDFMediaRadar_WhitePaper_DigitalPolitical_FIN.PDF
MediaRadar_WhitePaper_DigitalPolitical_FIN.PDFJesse Sherb
 

Viewers also liked (11)

erwin dizon updated resume july 2016
erwin dizon updated resume july 2016erwin dizon updated resume july 2016
erwin dizon updated resume july 2016
 
Tutoriel powerpoint
Tutoriel powerpointTutoriel powerpoint
Tutoriel powerpoint
 
1 a shakhova_final
1 a shakhova_final1 a shakhova_final
1 a shakhova_final
 
MRE Westlandse Zoom
MRE Westlandse ZoomMRE Westlandse Zoom
MRE Westlandse Zoom
 
Year 6 lesson plan - digital information
Year 6 lesson plan - digital informationYear 6 lesson plan - digital information
Year 6 lesson plan - digital information
 
Kazue Nakahara PP WD
Kazue Nakahara PP WDKazue Nakahara PP WD
Kazue Nakahara PP WD
 
An Act Amending Republic Act No. 9520
An Act Amending Republic Act No. 9520An Act Amending Republic Act No. 9520
An Act Amending Republic Act No. 9520
 
Coop First: how non-zero-sum games are reshaping our digital landscape
Coop First: how non-zero-sum games are reshaping our digital landscapeCoop First: how non-zero-sum games are reshaping our digital landscape
Coop First: how non-zero-sum games are reshaping our digital landscape
 
Community pharmacy
Community pharmacyCommunity pharmacy
Community pharmacy
 
NSCC Agri Tourism (1)
NSCC  Agri Tourism (1)NSCC  Agri Tourism (1)
NSCC Agri Tourism (1)
 
MediaRadar_WhitePaper_DigitalPolitical_FIN.PDF
MediaRadar_WhitePaper_DigitalPolitical_FIN.PDFMediaRadar_WhitePaper_DigitalPolitical_FIN.PDF
MediaRadar_WhitePaper_DigitalPolitical_FIN.PDF
 

Similar to A Python Crash Course

An Introduction to Scala (2014)
An Introduction to Scala (2014)An Introduction to Scala (2014)
An Introduction to Scala (2014)William Narmontas
 
Class 6: Lists & dictionaries
Class 6: Lists & dictionariesClass 6: Lists & dictionaries
Class 6: Lists & dictionariesMarc Gouw
 
CoderDojo: Intermediate Python programming course
CoderDojo: Intermediate Python programming courseCoderDojo: Intermediate Python programming course
CoderDojo: Intermediate Python programming courseAlexander Galkin
 
The (unknown) collections module
The (unknown) collections moduleThe (unknown) collections module
The (unknown) collections modulePablo Enfedaque
 
Python Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard WayPython Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard WayUtkarsh Sengar
 
Python_Cheat_Sheet_Keywords_1664634397.pdf
Python_Cheat_Sheet_Keywords_1664634397.pdfPython_Cheat_Sheet_Keywords_1664634397.pdf
Python_Cheat_Sheet_Keywords_1664634397.pdfsagar414433
 
Python_Cheat_Sheet_Keywords_1664634397.pdf
Python_Cheat_Sheet_Keywords_1664634397.pdfPython_Cheat_Sheet_Keywords_1664634397.pdf
Python_Cheat_Sheet_Keywords_1664634397.pdfsagar414433
 
Snakes for Camels
Snakes for CamelsSnakes for Camels
Snakes for Camelsmiquelruizm
 
Becoming a Pythonist
Becoming a PythonistBecoming a Pythonist
Becoming a PythonistRaji Engg
 
Beginners python cheat sheet - Basic knowledge
Beginners python cheat sheet - Basic knowledge Beginners python cheat sheet - Basic knowledge
Beginners python cheat sheet - Basic knowledge O T
 
What I learned from Seven Languages in Seven Weeks (IPRUG)
What I learned from Seven Languages in Seven Weeks (IPRUG)What I learned from Seven Languages in Seven Weeks (IPRUG)
What I learned from Seven Languages in Seven Weeks (IPRUG)Kerry Buckley
 
Byterun, a Python bytecode interpreter - Allison Kaptur at NYCPython
Byterun, a Python bytecode interpreter - Allison Kaptur at NYCPythonByterun, a Python bytecode interpreter - Allison Kaptur at NYCPython
Byterun, a Python bytecode interpreter - Allison Kaptur at NYCPythonakaptur
 
Introduction to Python
Introduction to PythonIntroduction to Python
Introduction to PythonUC San Diego
 

Similar to A Python Crash Course (20)

ch1_slides.pdf
ch1_slides.pdfch1_slides.pdf
ch1_slides.pdf
 
Dynamic Python
Dynamic PythonDynamic Python
Dynamic Python
 
An Introduction to Scala (2014)
An Introduction to Scala (2014)An Introduction to Scala (2014)
An Introduction to Scala (2014)
 
Class 6: Lists & dictionaries
Class 6: Lists & dictionariesClass 6: Lists & dictionaries
Class 6: Lists & dictionaries
 
CoderDojo: Intermediate Python programming course
CoderDojo: Intermediate Python programming courseCoderDojo: Intermediate Python programming course
CoderDojo: Intermediate Python programming course
 
Python for Dummies
Python for DummiesPython for Dummies
Python for Dummies
 
The (unknown) collections module
The (unknown) collections moduleThe (unknown) collections module
The (unknown) collections module
 
Python Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard WayPython Workshop - Learn Python the Hard Way
Python Workshop - Learn Python the Hard Way
 
Python_Cheat_Sheet_Keywords_1664634397.pdf
Python_Cheat_Sheet_Keywords_1664634397.pdfPython_Cheat_Sheet_Keywords_1664634397.pdf
Python_Cheat_Sheet_Keywords_1664634397.pdf
 
Python_Cheat_Sheet_Keywords_1664634397.pdf
Python_Cheat_Sheet_Keywords_1664634397.pdfPython_Cheat_Sheet_Keywords_1664634397.pdf
Python_Cheat_Sheet_Keywords_1664634397.pdf
 
Course set three full notes
Course set three full notesCourse set three full notes
Course set three full notes
 
Snakes for Camels
Snakes for CamelsSnakes for Camels
Snakes for Camels
 
Becoming a Pythonist
Becoming a PythonistBecoming a Pythonist
Becoming a Pythonist
 
Beginners python cheat sheet - Basic knowledge
Beginners python cheat sheet - Basic knowledge Beginners python cheat sheet - Basic knowledge
Beginners python cheat sheet - Basic knowledge
 
1. python
1. python1. python
1. python
 
Python cheatsheet for beginners
Python cheatsheet for beginnersPython cheatsheet for beginners
Python cheatsheet for beginners
 
A bit about Scala
A bit about ScalaA bit about Scala
A bit about Scala
 
What I learned from Seven Languages in Seven Weeks (IPRUG)
What I learned from Seven Languages in Seven Weeks (IPRUG)What I learned from Seven Languages in Seven Weeks (IPRUG)
What I learned from Seven Languages in Seven Weeks (IPRUG)
 
Byterun, a Python bytecode interpreter - Allison Kaptur at NYCPython
Byterun, a Python bytecode interpreter - Allison Kaptur at NYCPythonByterun, a Python bytecode interpreter - Allison Kaptur at NYCPython
Byterun, a Python bytecode interpreter - Allison Kaptur at NYCPython
 
Introduction to Python
Introduction to PythonIntroduction to Python
Introduction to Python
 

Recently uploaded

SaaStr Workshop Wednesday w: Jason Lemkin, SaaStr
SaaStr Workshop Wednesday w: Jason Lemkin, SaaStrSaaStr Workshop Wednesday w: Jason Lemkin, SaaStr
SaaStr Workshop Wednesday w: Jason Lemkin, SaaStrsaastr
 
Presentation on Engagement in Book Clubs
Presentation on Engagement in Book ClubsPresentation on Engagement in Book Clubs
Presentation on Engagement in Book Clubssamaasim06
 
George Lever - eCommerce Day Chile 2024
George Lever -  eCommerce Day Chile 2024George Lever -  eCommerce Day Chile 2024
George Lever - eCommerce Day Chile 2024eCommerce Institute
 
Re-membering the Bard: Revisiting The Compleat Wrks of Wllm Shkspr (Abridged)...
Re-membering the Bard: Revisiting The Compleat Wrks of Wllm Shkspr (Abridged)...Re-membering the Bard: Revisiting The Compleat Wrks of Wllm Shkspr (Abridged)...
Re-membering the Bard: Revisiting The Compleat Wrks of Wllm Shkspr (Abridged)...Hasting Chen
 
CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...
CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...
CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...henrik385807
 
ANCHORING SCRIPT FOR A CULTURAL EVENT.docx
ANCHORING SCRIPT FOR A CULTURAL EVENT.docxANCHORING SCRIPT FOR A CULTURAL EVENT.docx
ANCHORING SCRIPT FOR A CULTURAL EVENT.docxNikitaBankoti2
 
Call Girls in Sarojini Nagar Market Delhi 💯 Call Us 🔝8264348440🔝
Call Girls in Sarojini Nagar Market Delhi 💯 Call Us 🔝8264348440🔝Call Girls in Sarojini Nagar Market Delhi 💯 Call Us 🔝8264348440🔝
Call Girls in Sarojini Nagar Market Delhi 💯 Call Us 🔝8264348440🔝soniya singh
 
CTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdf
CTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdfCTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdf
CTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdfhenrik385807
 
Mohammad_Alnahdi_Oral_Presentation_Assignment.pptx
Mohammad_Alnahdi_Oral_Presentation_Assignment.pptxMohammad_Alnahdi_Oral_Presentation_Assignment.pptx
Mohammad_Alnahdi_Oral_Presentation_Assignment.pptxmohammadalnahdi22
 
WhatsApp 📞 9892124323 ✅Call Girls In Juhu ( Mumbai )
WhatsApp 📞 9892124323 ✅Call Girls In Juhu ( Mumbai )WhatsApp 📞 9892124323 ✅Call Girls In Juhu ( Mumbai )
WhatsApp 📞 9892124323 ✅Call Girls In Juhu ( Mumbai )Pooja Nehwal
 
Andrés Ramírez Gossler, Facundo Schinnea - eCommerce Day Chile 2024
Andrés Ramírez Gossler, Facundo Schinnea - eCommerce Day Chile 2024Andrés Ramírez Gossler, Facundo Schinnea - eCommerce Day Chile 2024
Andrés Ramírez Gossler, Facundo Schinnea - eCommerce Day Chile 2024eCommerce Institute
 
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...Salam Al-Karadaghi
 
No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...
No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...
No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...Sheetaleventcompany
 
Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...
Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...
Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...Kayode Fayemi
 
Open Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdf
Open Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdfOpen Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdf
Open Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdfhenrik385807
 
BDSM⚡Call Girls in Sector 93 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 93 Noida Escorts >༒8448380779 Escort ServiceBDSM⚡Call Girls in Sector 93 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 93 Noida Escorts >༒8448380779 Escort ServiceDelhi Call girls
 
Microsoft Copilot AI for Everyone - created by AI
Microsoft Copilot AI for Everyone - created by AIMicrosoft Copilot AI for Everyone - created by AI
Microsoft Copilot AI for Everyone - created by AITatiana Gurgel
 
Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...
Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...
Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...Pooja Nehwal
 
Introduction to Prompt Engineering (Focusing on ChatGPT)
Introduction to Prompt Engineering (Focusing on ChatGPT)Introduction to Prompt Engineering (Focusing on ChatGPT)
Introduction to Prompt Engineering (Focusing on ChatGPT)Chameera Dedduwage
 
Call Girl Number in Khar Mumbai📲 9892124323 💞 Full Night Enjoy
Call Girl Number in Khar Mumbai📲 9892124323 💞 Full Night EnjoyCall Girl Number in Khar Mumbai📲 9892124323 💞 Full Night Enjoy
Call Girl Number in Khar Mumbai📲 9892124323 💞 Full Night EnjoyPooja Nehwal
 

Recently uploaded (20)

SaaStr Workshop Wednesday w: Jason Lemkin, SaaStr
SaaStr Workshop Wednesday w: Jason Lemkin, SaaStrSaaStr Workshop Wednesday w: Jason Lemkin, SaaStr
SaaStr Workshop Wednesday w: Jason Lemkin, SaaStr
 
Presentation on Engagement in Book Clubs
Presentation on Engagement in Book ClubsPresentation on Engagement in Book Clubs
Presentation on Engagement in Book Clubs
 
George Lever - eCommerce Day Chile 2024
George Lever -  eCommerce Day Chile 2024George Lever -  eCommerce Day Chile 2024
George Lever - eCommerce Day Chile 2024
 
Re-membering the Bard: Revisiting The Compleat Wrks of Wllm Shkspr (Abridged)...
Re-membering the Bard: Revisiting The Compleat Wrks of Wllm Shkspr (Abridged)...Re-membering the Bard: Revisiting The Compleat Wrks of Wllm Shkspr (Abridged)...
Re-membering the Bard: Revisiting The Compleat Wrks of Wllm Shkspr (Abridged)...
 
CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...
CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...
CTAC 2024 Valencia - Sven Zoelle - Most Crucial Invest to Digitalisation_slid...
 
ANCHORING SCRIPT FOR A CULTURAL EVENT.docx
ANCHORING SCRIPT FOR A CULTURAL EVENT.docxANCHORING SCRIPT FOR A CULTURAL EVENT.docx
ANCHORING SCRIPT FOR A CULTURAL EVENT.docx
 
Call Girls in Sarojini Nagar Market Delhi 💯 Call Us 🔝8264348440🔝
Call Girls in Sarojini Nagar Market Delhi 💯 Call Us 🔝8264348440🔝Call Girls in Sarojini Nagar Market Delhi 💯 Call Us 🔝8264348440🔝
Call Girls in Sarojini Nagar Market Delhi 💯 Call Us 🔝8264348440🔝
 
CTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdf
CTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdfCTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdf
CTAC 2024 Valencia - Henrik Hanke - Reduce to the max - slideshare.pdf
 
Mohammad_Alnahdi_Oral_Presentation_Assignment.pptx
Mohammad_Alnahdi_Oral_Presentation_Assignment.pptxMohammad_Alnahdi_Oral_Presentation_Assignment.pptx
Mohammad_Alnahdi_Oral_Presentation_Assignment.pptx
 
WhatsApp 📞 9892124323 ✅Call Girls In Juhu ( Mumbai )
WhatsApp 📞 9892124323 ✅Call Girls In Juhu ( Mumbai )WhatsApp 📞 9892124323 ✅Call Girls In Juhu ( Mumbai )
WhatsApp 📞 9892124323 ✅Call Girls In Juhu ( Mumbai )
 
Andrés Ramírez Gossler, Facundo Schinnea - eCommerce Day Chile 2024
Andrés Ramírez Gossler, Facundo Schinnea - eCommerce Day Chile 2024Andrés Ramírez Gossler, Facundo Schinnea - eCommerce Day Chile 2024
Andrés Ramírez Gossler, Facundo Schinnea - eCommerce Day Chile 2024
 
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...
Exploring protein-protein interactions by Weak Affinity Chromatography (WAC) ...
 
No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...
No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...
No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...
 
Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...
Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...
Governance and Nation-Building in Nigeria: Some Reflections on Options for Po...
 
Open Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdf
Open Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdfOpen Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdf
Open Source Strategy in Logistics 2015_Henrik Hankedvz-d-nl-log-conference.pdf
 
BDSM⚡Call Girls in Sector 93 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 93 Noida Escorts >༒8448380779 Escort ServiceBDSM⚡Call Girls in Sector 93 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 93 Noida Escorts >༒8448380779 Escort Service
 
Microsoft Copilot AI for Everyone - created by AI
Microsoft Copilot AI for Everyone - created by AIMicrosoft Copilot AI for Everyone - created by AI
Microsoft Copilot AI for Everyone - created by AI
 
Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...
Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...
Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...
 
Introduction to Prompt Engineering (Focusing on ChatGPT)
Introduction to Prompt Engineering (Focusing on ChatGPT)Introduction to Prompt Engineering (Focusing on ChatGPT)
Introduction to Prompt Engineering (Focusing on ChatGPT)
 
Call Girl Number in Khar Mumbai📲 9892124323 💞 Full Night Enjoy
Call Girl Number in Khar Mumbai📲 9892124323 💞 Full Night EnjoyCall Girl Number in Khar Mumbai📲 9892124323 💞 Full Night Enjoy
Call Girl Number in Khar Mumbai📲 9892124323 💞 Full Night Enjoy
 

A Python Crash Course

  • 1. A Python Crash Course Alex-P. Natsios – George Stoumpos Technological Institute of Larissa 5 Dec 2012 Alex-P. Natsios – George Stoumpos Diving into Python
  • 2. A few words about python Characteristics: created and published by Guido Van Rossum in 1991 Interpreted Multiplatform Object Oriented Dynamic Typing Coding Style Alex-P. Natsios – George Stoumpos Diving into Python
  • 3. How to Start Python? You can either run python from a script or Interactively: Interactive: (using the interpreter to run python code) $ python >>> print ”Hello there!” Hello there From a script: (using a text file with python code) $ python myscript.py Hello there! $ Alex-P. Natsios – George Stoumpos Diving into Python
  • 4. Data types in Python Numbers: Integer(42), float(13.37), complex(12+3n) Strings: ”nothing interesting here move along” Dictionaries: dict = {name : ‘Maria’, age : 22, 42 : ‘haha’ } Lists: list = [1, ‘classic’, 2, ‘boring’] Tuples: tuple = ( 1, 2, 42, ‘Maria’, (1,2,3) ) Objects: instance = Class(‘foobar’) Modules: import antigravity Alex-P. Natsios – George Stoumpos Diving into Python
  • 5. Python has objects! Everything in python is an object and every object has its attributes. Object Attributes: >>> name = ‘maria’ >>> name.index(‘i’) 3 breaking down the above statement we have: variable delimeter attribute parameters (if any) Alex-P. Natsios – George Stoumpos Diving into Python
  • 6. Another peek in Attributes/Methods Attributes?! Methods?! i can’t remember all these stuff! Lucky you! you dont have to know all of them using dir(): dir allows you to peek into an object and learn about its supported methods lets take a look at a list for example. >>> dir(list): [‘append’, ‘extend’, ‘insert’, ‘remove’, ‘pop’, ‘index’, ‘count’, ‘sort’, ‘reverse’] Alex-P. Natsios – George Stoumpos Diving into Python
  • 7. Back to data type fun Dictionaries Example >>> dict = {name : ‘Maria’, age : 22, 42 : ‘haha’ } >>> dict[’age’] 22 >>> ‘name’ in dict True >>> del dict[’age’] (we could also use pop to also return the removed key’s value) Alex-P. Natsios – George Stoumpos Diving into Python
  • 8. Back to data type fun Lists Example >>> list = [1, ‘classic’, 2, ‘boring’] >>> list.append(”Maria”) >>> list [1, ‘classic’, 2 ‘boring’, ‘Maria’] >>> list.insert(4,”Alex”) >>> list [1, ‘classic’, 2 ‘boring’, ‘Alex’, ‘Maria’] Alex-P. Natsios – George Stoumpos Diving into Python
  • 9. Back to data type fun Tuples Tuples also known as Sequences and as such they are ordered. you can also slice them using the slice operator: Slice Operator mysequence[ i : j ] with ‘i’ and ‘j’ being your range in the sequence ( i = start , j = one past the end ) Example tuple = ( 1, 2, 42, ‘Maria’, (1,2,3) ) >>> tuple[0] 1 >>> tuple[3] ‘Maria’ >>> tuple[1:2] (1,42) >>> tuple[-1] (1,2,3) >>> tuple[3:] (‘Maria’,(1,2,3)) Alex-P. Natsios – George Stoumpos Diving into Python
  • 10. Python type mutability The value of some objects can change. Objects whose value can change are said to be mutable; objects whose value is unchangeable once they are created are called immutable. mutable Dictionaries, Lists immutable Numbers, Strings, Tuples, Frozensets Alex-P. Natsios – George Stoumpos Diving into Python
  • 11. Flow Control Conditionals IF statement name = ”Maria” if name == ”Maria”: print ”Hello Maria!” elif name == ”George”: print ”Hello George!” else: print ”Hello stranger!” Alex-P. Natsios – George Stoumpos Diving into Python
  • 12. Flow Control Loops While loop i = 0 while i<5: print i i += 1 Alex-P. Natsios – George Stoumpos Diving into Python
  • 13. Flow Control Loops for loop for item in range(1,100): print item yet another for loop names = (”Maria”, ”George”, ”Helen”, ”Alex”) for item in names: print item Alex-P. Natsios – George Stoumpos Diving into Python
  • 14. Numeric Operators + - * / Your everyday numeric operations. % Modulus - Divides left hand operant by right hand operant. Returns ‘Remainder’ ** Exponent - performs exponential calculation on operant. // Floor Division - division operant where the digits after the result’s decimal point are removed. Alex-P. Natsios – George Stoumpos Diving into Python
  • 15. Function Definition a simple function >>> def foo(bar): print bar >>> foo(123) 123 Alex-P. Natsios – George Stoumpos Diving into Python
  • 16. Class Definition a simple class class AddressBookEntry(object): def init (self, name, phone): self.name = name self.phone = phone def update phone(self, phone): self.phone = phone Alex-P. Natsios – George Stoumpos Diving into Python