SlideShare une entreprise Scribd logo
1  sur  66
Télécharger pour lire hors ligne
Leonardo Jimenez
@leonardoajim
ljimenez@stancedata.com
Python for Dummies
Python for Dummies
Newbies
What is Python or What
the hell I am doing here?
- Programming Language
-Easy to Read
-Productive ( ha ha, Java programmer!!)
-Portable (.net anyone?)
-Big Library ( We got all type of wheels!)
...Fun
Created by Guido Van Rossum
I am in the same
picture, awesome!!
This is Guido
Where is python used?
Let's Begin
http://python.org/download/
Python Building Blocks
Interpreted Language
Compiler Computer
Python Building Blocks
A language is made by Statements
An statement is an order of what You want the
computer to do.
Examples:
Print in the screen the name of the user
Create a new windows
Calculate age
Show Image
Python Building Blocks
A language is made by Statements
An statement is an order of what You want the computer to do.
Examples:
Python Building Blocks
Variable
We have to keep track of a lot of information.
Examples:
"Engineer"
01/27/2013
example@example.com
12,0000
Python Building Blocks
Variable
Reserved Words.
and del from not while
as elif global or with
assert else if pass yield
break except import print
class exec in raise
finally is return continue
def for lambda try
Python Building Blocks
Variables
Python Building Blocks
Variables
title party_date email debt
Python Building Blocks
Variables
"Engineer" 01/27/2013
e@ex.com 12000
title party_date email debt
Python Building Blocks
Variables
Are Key sensitives:
myVariable != MyVariable
Python Building Blocks
Variables
Are Key sensitives:
myVariable != MyVariable
Python Building Blocks
Object
Int ex.1234 long ex. 35L float1234 35L 3.1415
bool True False
str
"Hello World" , 'simply "hello" ' """ Complex strings"""
list
dict
tuple
college = [ "awful teachers", "boring books", "some partying"]
words_said_by_women_meaning= { "best_friend" : " You lose your chance"}
(1, 'other item', 54, 'U')
Python Building Blocks -Int
Int ex.1234 long ex. 35L float1234 35L 3.1415
Naturals Complex
Numbers ( a + bj)
Real numbers
(a+bj)
Basic operations
+,-,*,/ , %, **
Compare
=, <, >, !=
Division by integers
Division by zero
Python Building Blocks -Int
Python Building Blocks
Test Pause
Work with Variables.py
Python Building Blocks -Int/LInt
Python Building Blocks -String
Python Building Blocks -String
"Hello World"
0 1 2
3
4 5 6 7
8
9 10
Python Building Blocks -String
Python Building Blocks -String
Some useful methods:
str.capitalize()
str.count(sub[, start[, end]])
str.find(sub, [,start[, end]])
str.index(sub, [,start[, end]])
str.replace(old, mes[,count])
str.lower() / str.upper()
str.join(iterable)
str.split([sep[,maxsplit]])
Pretty function
len(str)
Python Building Blocks -Lists
A list if a basic structure on python, is defined as :
list = [ n1
, n2
, .... nn
] , where N is any basic python data
structure
Python Building Blocks -Lists
A list if a basic structure on python, is defined as :
list = [ n1
, n2
, .... nn
] , where N is any basic python data
structure
training = [ ]
Training
Python Building Blocks -Lists
A list if a basic structure on python, is defined as :
list = [ n1
, n2
, .... nn
] , where N is any basic python data
structure
training = [ ]
training.append(50)
training.append(60)
training.append("Mouse")
[0]
[1]
[2]
Training
50
"Mouse"
60
Python Building Blocks -Lists
A list if a basic structure on python, is defined as :
list = [ n1
, n2
, .... nn
] , where N is any basic python data
structure
training = [ ]
training.append(50)
training.append(60)
training.append("Mouse")
[0]
[1]
[2]
Training
50
"Mouse"
60
Index
Python Building Blocks -Lists
A list if a basic structure on python, is defined as :
list = [ n1
, n2
, .... nn
] , where N is any basic python data
structure
training = [ ]
training.append(50)
training.append(60)
training.append("Mouse")
Another way of creating it is:
training = [ 50, 60, "Mouse"]
[0]
[1]
[2]
Training
50
"Mouse"
60
Python Building Blocks -Lists
A list if a basic structure on python, is defined as :
list = [ n1
, n2
, .... nn
] , where N is any basic python data
structure
training.extend([3])
[0]
[1]
[2]
[3]
Training
50
"Mouse"
60
3
Python Building Blocks -Lists
A list if a basic structure on python, is defined as :
list = [ n1
, n2
, .... nn
] , where N is any basic python data
structure
training.append(50)
[0]
[1]
[2]
[3]
[4]
Training
50
"Mouse"
60
3
50
Python Building Blocks -Lists
A list if a basic structure on python, is defined as :
list = [ n1
, n2
, .... nn
] , where N is any basic python data
structure
training.remove(50)
[0]
[1]
[2]
[3]
Training
50
"Mouse"
60
3
Python Building Blocks -Lists
A list if a basic structure on python, is defined as :
list = [ n1
, n2
, .... nn
] , where N is any basic python data
structure
training.remove(50)
[0]
[1]
[2]
[3]
Training
50
"Mouse"
60
3
Python Building Blocks -Lists
A list if a basic structure on python, is defined as :
list = [ n1
, n2
, .... nn
] , where N is any basic python data
structure
training.pop()
[0]
[1]
[2]
Training
50
"Mouse"
60
3
Python Building Blocks -Lists
A list if a basic structure on python, is defined as :
list = [ n1
, n2
, .... nn
] , where N is any basic python data
structure
training.pop()
[0]
[1]
[2]
Training
50
"Mouse"
60
3
Python Building Blocks -Lists
We treated:
list.append(x)*
list.extend(L)*
list.remove(x)*
Other Important functions:
list.insert(i, x)*
list.pop([i])*
list.count(x)*
list.sort()
list.reverse()
*Notes : x: element, i : index, l: list
Python Building Blocks -Lists
We treated:
list.append(x)*
list.extend(L)*
list.remove(x)*
Other Important functions:
list.insert(i, x)*
list.pop([i])*
list.count(x)*
list.sort()
list.reverse()
*Notes : x: element, i : index, l: list
Python Building Blocks -Tuples
Remember the lists, they are the same but You can't modify
them. They are immutable.
Python Building Blocks -Tuples
Remember the lists, they are the same but You
can't modify them. They are immutable.
Let's have the immutability talk!
Python Building Blocks -Dictionaries
Also called Hash or associative Array. Is defined as a collection
of references called keys that point to a value.
dictionary = {
'key1
' : value1
,
'key2
' : value2
,
.....................
'keyN
' : valueN
,
}
Python Building Blocks -Dictionaries
Also called Hash or associative Array. Is defined as a collection
of references called keys that point to a value.
dictionary = {
'key1
' : value1
,
'key2
' : value2
,
.....................
'keyN
' : valueN
,
}
Python Building Blocks -Dictionaries
Also called Hash or associative Array. Is defined as a collection
of references called keys that point to a value.
Key
Value
Python Building Blocks -Dictionaries
Also called Hash or associative Array. Is defined as a collection
of references called keys that point to a value.
You can initialize a Dictionary with the following:
d = {} #empty dictionary
d = dict()#empty dictionary
d = { "hello": "World"}
d = dict(hello="world")
Python Building Blocks -Dictionaries
Some Useful Dictionary methods:
len(d)
d[key]
d[key] = value
del d[key]
key in d / key not in d
d.clear()
d.has_key(key)
d.keys()
d.values()
pop(key[, default])
popitem()
Python Building Blocks -Other Structures
Sets
Frozensets
Files
Python Functions or How to be lazy with style?
1- def goes before the function you are defining. the function name can't be name of
another python defined function.
2 - It can have multiple arguments.
4- All functions must have a return value
Functions are reusable block
codes.
def function_name(argument1
, argument2
,.. .., argumentn
):
code block
return result
1 2
3
4
Python Functions or How to be lazy with style?
Some examples:
Control Structures, What If...?
Conditionals
if condition :
do something
If you have more than one option else comes handy
if condition :
do something
else:
do something else
Control Structures, What If...?
Conditionals
When if and else is not enough, maybe you need
elif
if condition :
do something
elif:
do something different
else:
do something else
Control Structures, What are you waiting for?
Conditionals
The for is one of the most used control structures
example 1:
for i in structure :
do something with i block
example 2:
for i in range(n):
do something with i block
Control Structures, While We wait...
Conditionals
The while is another control structure used
example 1:
variable = value
while i has condition :
do something with i block
Control Structures, Other things
Somethings of interest
Continue:
jumps one step
Break:
break the loop
List Comprehension (optional)
Somethings of interest
[ F(x) for x in object/range + conditional]
[F(x1
, x2
, ... xn
) for (x1
, x2
, ... xn
) in object/range(x1
, x2
, ... xn
) +
conditional(x1
, x2
, ... xn
)]
Tuple Comprehension
Somethings of interest
tuple([ F(x) for x in object/range + conditional])
tuple([F(x1
, x2
, ... xn
) for (x1
, x2
, ... xn
) in object/range(x1
, x2
, ...
xn
) + conditional(x1
, x2
, ... xn
)])
Tuple Comprehension
Somethings of interest
tuple([ F(x) for x in object/range + conditional])
tuple([F(x1
, x2
, ... xn
) for (x1
, x2
, ... xn
) in object/range(x1
, x2
, ...
xn
) + conditional(x1
, x2
, ... xn
)])
Dictionary Comprehension
Somethings of interest
{ F(x): G(x) for x in object/range + conditional}
{F(x1
, x2
, ... xn
):G(x1
, x2
, ... xn
) for (x1
, x2
, ... xn
) in object/range
(x1
, x2
, ... xn
) + conditional(x1
, x2
, ... xn
)}
The Files talk
The way Python interacts with files.
The Files examples
# Open a file
fo = open("foo.txt", "wb")
print "Name of the file: ", fo.name
print "Closed or not : ", fo.closed
print "Opening mode : ", fo.mode
print "Softspace flag : ", fo.softspace
The Files examples
class BankAccount(object):
def __init__(self, initial_balance=0):
self.balance = initial_balance
def deposit(self, amount):
self.balance += amount
def withdraw(self, amount):
self.balance -= amount
def overdrawn(self):
return self.balance < 0
my_account = BankAccount(15)
my_account.withdraw(5)
print my_account.balance
Python Building Blocks -Dir
Using "dir":
One of the most beautiful functions in
Python to study object types.
Looking for Help
- Exceptions
- Dir
- Documentation (help)
- Documentation (developer)
- Stackoverflow.com
- IRC
- Python Usergroup
Python Building Blocks -Int
dir is not clear enough, so I made a
function
Internal Attributes
Methods We care
Looking for Help
- Dir
- Documentation (help)
- Documentation (developer)
- Stackoverflow.com
- IRC
- Python Usergroup
Questions?

Contenu connexe

Tendances

Matlab and Python: Basic Operations
Matlab and Python: Basic OperationsMatlab and Python: Basic Operations
Matlab and Python: Basic OperationsWai Nwe Tun
 
Introduction to Python and TensorFlow
Introduction to Python and TensorFlowIntroduction to Python and TensorFlow
Introduction to Python and TensorFlowBayu Aldi Yansyah
 
Python language data types
Python language data typesPython language data types
Python language data typesHoang Nguyen
 
Learn python in 20 minutes
Learn python in 20 minutesLearn python in 20 minutes
Learn python in 20 minutesSidharth Nadhan
 
java 8 Hands on Workshop
java 8 Hands on Workshopjava 8 Hands on Workshop
java 8 Hands on WorkshopJeanne Boyarsky
 
Python Programming: Data Structure
Python Programming: Data StructurePython Programming: Data Structure
Python Programming: Data StructureChan Shik Lim
 
Learn python - for beginners - part-2
Learn python - for beginners - part-2Learn python - for beginners - part-2
Learn python - for beginners - part-2RajKumar Rampelli
 
15. Streams Files and Directories
15. Streams Files and Directories 15. Streams Files and Directories
15. Streams Files and Directories Intro C# Book
 
Python Datatypes by SujithKumar
Python Datatypes by SujithKumarPython Datatypes by SujithKumar
Python Datatypes by SujithKumarSujith Kumar
 
Python 2.5 reference card (2009)
Python 2.5 reference card (2009)Python 2.5 reference card (2009)
Python 2.5 reference card (2009)gekiaruj
 
Mementopython3 english
Mementopython3 englishMementopython3 english
Mementopython3 englishssuser442080
 
Python Puzzlers - 2016 Edition
Python Puzzlers - 2016 EditionPython Puzzlers - 2016 Edition
Python Puzzlers - 2016 EditionNandan Sawant
 
Python dictionary : past, present, future
Python dictionary: past, present, futurePython dictionary: past, present, future
Python dictionary : past, present, futuredelimitry
 
13. Java text processing
13.  Java text processing13.  Java text processing
13. Java text processingIntro C# Book
 
Python 101++: Let's Get Down to Business!
Python 101++: Let's Get Down to Business!Python 101++: Let's Get Down to Business!
Python 101++: Let's Get Down to Business!Paige Bailey
 
Intro to Python (High School) Unit #2
Intro to Python (High School) Unit #2Intro to Python (High School) Unit #2
Intro to Python (High School) Unit #2Jay Coskey
 
Declarative Thinking, Declarative Practice
Declarative Thinking, Declarative PracticeDeclarative Thinking, Declarative Practice
Declarative Thinking, Declarative PracticeKevlin Henney
 
Datastructures in python
Datastructures in pythonDatastructures in python
Datastructures in pythonhydpy
 
Programming in Python
Programming in Python Programming in Python
Programming in Python Tiji Thomas
 
Python Training Tutorial for Frreshers
Python Training Tutorial for FrreshersPython Training Tutorial for Frreshers
Python Training Tutorial for Frreshersrajkamaltibacademy
 

Tendances (20)

Matlab and Python: Basic Operations
Matlab and Python: Basic OperationsMatlab and Python: Basic Operations
Matlab and Python: Basic Operations
 
Introduction to Python and TensorFlow
Introduction to Python and TensorFlowIntroduction to Python and TensorFlow
Introduction to Python and TensorFlow
 
Python language data types
Python language data typesPython language data types
Python language data types
 
Learn python in 20 minutes
Learn python in 20 minutesLearn python in 20 minutes
Learn python in 20 minutes
 
java 8 Hands on Workshop
java 8 Hands on Workshopjava 8 Hands on Workshop
java 8 Hands on Workshop
 
Python Programming: Data Structure
Python Programming: Data StructurePython Programming: Data Structure
Python Programming: Data Structure
 
Learn python - for beginners - part-2
Learn python - for beginners - part-2Learn python - for beginners - part-2
Learn python - for beginners - part-2
 
15. Streams Files and Directories
15. Streams Files and Directories 15. Streams Files and Directories
15. Streams Files and Directories
 
Python Datatypes by SujithKumar
Python Datatypes by SujithKumarPython Datatypes by SujithKumar
Python Datatypes by SujithKumar
 
Python 2.5 reference card (2009)
Python 2.5 reference card (2009)Python 2.5 reference card (2009)
Python 2.5 reference card (2009)
 
Mementopython3 english
Mementopython3 englishMementopython3 english
Mementopython3 english
 
Python Puzzlers - 2016 Edition
Python Puzzlers - 2016 EditionPython Puzzlers - 2016 Edition
Python Puzzlers - 2016 Edition
 
Python dictionary : past, present, future
Python dictionary: past, present, futurePython dictionary: past, present, future
Python dictionary : past, present, future
 
13. Java text processing
13.  Java text processing13.  Java text processing
13. Java text processing
 
Python 101++: Let's Get Down to Business!
Python 101++: Let's Get Down to Business!Python 101++: Let's Get Down to Business!
Python 101++: Let's Get Down to Business!
 
Intro to Python (High School) Unit #2
Intro to Python (High School) Unit #2Intro to Python (High School) Unit #2
Intro to Python (High School) Unit #2
 
Declarative Thinking, Declarative Practice
Declarative Thinking, Declarative PracticeDeclarative Thinking, Declarative Practice
Declarative Thinking, Declarative Practice
 
Datastructures in python
Datastructures in pythonDatastructures in python
Datastructures in python
 
Programming in Python
Programming in Python Programming in Python
Programming in Python
 
Python Training Tutorial for Frreshers
Python Training Tutorial for FrreshersPython Training Tutorial for Frreshers
Python Training Tutorial for Frreshers
 

En vedette

Health 2.0 pre ga slides day 1 & change management
Health 2.0 pre ga slides day 1 & change managementHealth 2.0 pre ga slides day 1 & change management
Health 2.0 pre ga slides day 1 & change managementSalmaan Sana
 
Intro to Python Workshop San Diego, CA (January 19, 2013)
Intro to Python Workshop San Diego, CA (January 19, 2013)Intro to Python Workshop San Diego, CA (January 19, 2013)
Intro to Python Workshop San Diego, CA (January 19, 2013)Kendall
 
Программа Форума Промышленного маркетинга 2011
Программа Форума Промышленного маркетинга 2011Программа Форума Промышленного маркетинга 2011
Программа Форума Промышленного маркетинга 2011Agency of Industrial Marketing
 
Elizabath
ElizabathElizabath
ElizabathDYUTI
 
Verimatrix-Multi-network Solutions in the Real World - NexTV Mexico 2012
Verimatrix-Multi-network Solutions in the Real World - NexTV Mexico 2012Verimatrix-Multi-network Solutions in the Real World - NexTV Mexico 2012
Verimatrix-Multi-network Solutions in the Real World - NexTV Mexico 2012Verimatrix
 
Suzuki Violin Method Vol 01
Suzuki Violin Method   Vol 01Suzuki Violin Method   Vol 01
Suzuki Violin Method Vol 01Orquesta2009
 
Sao Paulo Multi-network Event 2012 - Network Broadcast
Sao Paulo Multi-network Event 2012 - Network BroadcastSao Paulo Multi-network Event 2012 - Network Broadcast
Sao Paulo Multi-network Event 2012 - Network BroadcastVerimatrix
 
A Study Of The Mental Health Awareness Among
A Study Of The Mental Health Awareness AmongA Study Of The Mental Health Awareness Among
A Study Of The Mental Health Awareness AmongDYUTI
 
Green Consultants- brief profile
Green Consultants- brief profileGreen Consultants- brief profile
Green Consultants- brief profileGunjan Bagaria
 
My Leaders & Role Models Coral
My Leaders & Role Models CoralMy Leaders & Role Models Coral
My Leaders & Role Models Coralguest706685d
 
Suzuki Violin Method Vol 01
Suzuki Violin Method   Vol 01Suzuki Violin Method   Vol 01
Suzuki Violin Method Vol 01Orquesta2009
 
Elizabath
ElizabathElizabath
ElizabathDYUTI
 

En vedette (20)

Welcome to Python
Welcome to PythonWelcome to Python
Welcome to Python
 
Health 2.0 pre ga slides day 1 & change management
Health 2.0 pre ga slides day 1 & change managementHealth 2.0 pre ga slides day 1 & change management
Health 2.0 pre ga slides day 1 & change management
 
Intro to Python Workshop San Diego, CA (January 19, 2013)
Intro to Python Workshop San Diego, CA (January 19, 2013)Intro to Python Workshop San Diego, CA (January 19, 2013)
Intro to Python Workshop San Diego, CA (January 19, 2013)
 
Python
Python Python
Python
 
Intro to Python
Intro to PythonIntro to Python
Intro to Python
 
Pràctica 1
Pràctica 1Pràctica 1
Pràctica 1
 
Программа Форума Промышленного маркетинга 2011
Программа Форума Промышленного маркетинга 2011Программа Форума Промышленного маркетинга 2011
Программа Форума Промышленного маркетинга 2011
 
Elizabath
ElizabathElizabath
Elizabath
 
Verimatrix-Multi-network Solutions in the Real World - NexTV Mexico 2012
Verimatrix-Multi-network Solutions in the Real World - NexTV Mexico 2012Verimatrix-Multi-network Solutions in the Real World - NexTV Mexico 2012
Verimatrix-Multi-network Solutions in the Real World - NexTV Mexico 2012
 
Suzuki Violin Method Vol 01
Suzuki Violin Method   Vol 01Suzuki Violin Method   Vol 01
Suzuki Violin Method Vol 01
 
Sao Paulo Multi-network Event 2012 - Network Broadcast
Sao Paulo Multi-network Event 2012 - Network BroadcastSao Paulo Multi-network Event 2012 - Network Broadcast
Sao Paulo Multi-network Event 2012 - Network Broadcast
 
Startups 101
Startups 101Startups 101
Startups 101
 
A Study Of The Mental Health Awareness Among
A Study Of The Mental Health Awareness AmongA Study Of The Mental Health Awareness Among
A Study Of The Mental Health Awareness Among
 
nogachevskiy
nogachevskiynogachevskiy
nogachevskiy
 
Little Bear Book
Little  Bear  BookLittle  Bear  Book
Little Bear Book
 
Green Consultants- brief profile
Green Consultants- brief profileGreen Consultants- brief profile
Green Consultants- brief profile
 
Deciding on the course and its objectives
Deciding on the course and its objectivesDeciding on the course and its objectives
Deciding on the course and its objectives
 
My Leaders & Role Models Coral
My Leaders & Role Models CoralMy Leaders & Role Models Coral
My Leaders & Role Models Coral
 
Suzuki Violin Method Vol 01
Suzuki Violin Method   Vol 01Suzuki Violin Method   Vol 01
Suzuki Violin Method Vol 01
 
Elizabath
ElizabathElizabath
Elizabath
 

Similaire à Python for Dummies

Profiling and optimization
Profiling and optimizationProfiling and optimization
Profiling and optimizationg3_nittala
 
Python Interview Questions | Python Interview Questions And Answers | Python ...
Python Interview Questions | Python Interview Questions And Answers | Python ...Python Interview Questions | Python Interview Questions And Answers | Python ...
Python Interview Questions | Python Interview Questions And Answers | Python ...Simplilearn
 
FUNDAMENTALS OF PYTHON LANGUAGE
 FUNDAMENTALS OF PYTHON LANGUAGE  FUNDAMENTALS OF PYTHON LANGUAGE
FUNDAMENTALS OF PYTHON LANGUAGE Saraswathi Murugan
 
Interview-level-QA-on-Python-Programming.pdf
Interview-level-QA-on-Python-Programming.pdfInterview-level-QA-on-Python-Programming.pdf
Interview-level-QA-on-Python-Programming.pdfExaminationSectionMR
 
unit (1)INTRODUCTION TO PYTHON course.pptx
unit (1)INTRODUCTION TO PYTHON course.pptxunit (1)INTRODUCTION TO PYTHON course.pptx
unit (1)INTRODUCTION TO PYTHON course.pptxusvirat1805
 
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
 
These questions will be a bit advanced level 2
These questions will be a bit advanced level 2These questions will be a bit advanced level 2
These questions will be a bit advanced level 2sadhana312471
 
Basic data types in python
Basic data types in pythonBasic data types in python
Basic data types in pythonsunilchute1
 
James Jesus Bermas on Crash Course on Python
James Jesus Bermas on Crash Course on PythonJames Jesus Bermas on Crash Course on Python
James Jesus Bermas on Crash Course on PythonCP-Union
 

Similaire à Python for Dummies (20)

Dynamic Python
Dynamic PythonDynamic Python
Dynamic Python
 
Profiling and optimization
Profiling and optimizationProfiling and optimization
Profiling and optimization
 
Python for beginners
Python for beginnersPython for beginners
Python for beginners
 
Python Interview Questions | Python Interview Questions And Answers | Python ...
Python Interview Questions | Python Interview Questions And Answers | Python ...Python Interview Questions | Python Interview Questions And Answers | Python ...
Python Interview Questions | Python Interview Questions And Answers | Python ...
 
Pythonppt28 11-18
Pythonppt28 11-18Pythonppt28 11-18
Pythonppt28 11-18
 
FUNDAMENTALS OF PYTHON LANGUAGE
 FUNDAMENTALS OF PYTHON LANGUAGE  FUNDAMENTALS OF PYTHON LANGUAGE
FUNDAMENTALS OF PYTHON LANGUAGE
 
Python for dummies
Python for dummiesPython for dummies
Python for dummies
 
Python 3.pptx
Python 3.pptxPython 3.pptx
Python 3.pptx
 
Interview-level-QA-on-Python-Programming.pdf
Interview-level-QA-on-Python-Programming.pdfInterview-level-QA-on-Python-Programming.pdf
Interview-level-QA-on-Python-Programming.pdf
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Python cheat-sheet
Python cheat-sheetPython cheat-sheet
Python cheat-sheet
 
PYTHON
PYTHONPYTHON
PYTHON
 
unit (1)INTRODUCTION TO PYTHON course.pptx
unit (1)INTRODUCTION TO PYTHON course.pptxunit (1)INTRODUCTION TO PYTHON course.pptx
unit (1)INTRODUCTION TO PYTHON course.pptx
 
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 tour
Python tourPython tour
Python tour
 
These questions will be a bit advanced level 2
These questions will be a bit advanced level 2These questions will be a bit advanced level 2
These questions will be a bit advanced level 2
 
Basic data types in python
Basic data types in pythonBasic data types in python
Basic data types in python
 
Python
PythonPython
Python
 
python1.ppt
python1.pptpython1.ppt
python1.ppt
 
James Jesus Bermas on Crash Course on Python
James Jesus Bermas on Crash Course on PythonJames Jesus Bermas on Crash Course on Python
James Jesus Bermas on Crash Course on Python
 

Plus de Leonardo Jimenez

Debugging para el no iniciado
Debugging para el no iniciadoDebugging para el no iniciado
Debugging para el no iniciadoLeonardo Jimenez
 
How to create developer communities
How to create developer communitiesHow to create developer communities
How to create developer communitiesLeonardo Jimenez
 
Pyladies Workshop (Spanish)
Pyladies Workshop (Spanish)Pyladies Workshop (Spanish)
Pyladies Workshop (Spanish)Leonardo Jimenez
 
Python Testing 101 with Selenium
Python Testing 101 with SeleniumPython Testing 101 with Selenium
Python Testing 101 with SeleniumLeonardo Jimenez
 
Presentación comunidades python dominicana
Presentación comunidades python dominicanaPresentación comunidades python dominicana
Presentación comunidades python dominicanaLeonardo Jimenez
 
The age of entrepreneurship
The age of entrepreneurshipThe age of entrepreneurship
The age of entrepreneurshipLeonardo Jimenez
 

Plus de Leonardo Jimenez (8)

Debugging para el no iniciado
Debugging para el no iniciadoDebugging para el no iniciado
Debugging para el no iniciado
 
How to create developer communities
How to create developer communitiesHow to create developer communities
How to create developer communities
 
Pyladies Workshop (Spanish)
Pyladies Workshop (Spanish)Pyladies Workshop (Spanish)
Pyladies Workshop (Spanish)
 
Python Testing 101 with Selenium
Python Testing 101 with SeleniumPython Testing 101 with Selenium
Python Testing 101 with Selenium
 
Lean startup 101
Lean startup 101Lean startup 101
Lean startup 101
 
Presentación comunidades python dominicana
Presentación comunidades python dominicanaPresentación comunidades python dominicana
Presentación comunidades python dominicana
 
The age of entrepreneurship
The age of entrepreneurshipThe age of entrepreneurship
The age of entrepreneurship
 
Genetica Mutaciones
Genetica MutacionesGenetica Mutaciones
Genetica Mutaciones
 

Dernier

Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...OnePlan Solutions
 
2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shards2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shardsChristopher Curtin
 
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...OnePlan Solutions
 
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...Bert Jan Schrijver
 
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptxThe Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptxRTS corp
 
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdfAndrey Devyatkin
 
Copilot para Microsoft 365 y Power Platform Copilot
Copilot para Microsoft 365 y Power Platform CopilotCopilot para Microsoft 365 y Power Platform Copilot
Copilot para Microsoft 365 y Power Platform CopilotEdgard Alejos
 
Data modeling 101 - Basics - Software Domain
Data modeling 101 - Basics - Software DomainData modeling 101 - Basics - Software Domain
Data modeling 101 - Basics - Software DomainAbdul Ahad
 
Introduction to Firebase Workshop Slides
Introduction to Firebase Workshop SlidesIntroduction to Firebase Workshop Slides
Introduction to Firebase Workshop Slidesvaideheekore1
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLionel Briand
 
Keeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldKeeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldRoberto Pérez Alcolea
 
VictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News UpdateVictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News UpdateVictoriaMetrics
 
Zer0con 2024 final share short version.pdf
Zer0con 2024 final share short version.pdfZer0con 2024 final share short version.pdf
Zer0con 2024 final share short version.pdfmaor17
 
Amazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilitiesAmazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilitiesKrzysztofKkol1
 
Osi security architecture in network.pptx
Osi security architecture in network.pptxOsi security architecture in network.pptx
Osi security architecture in network.pptxVinzoCenzo
 
Ronisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited CatalogueRonisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited Catalogueitservices996
 
SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?Alexandre Beguel
 
Effectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorEffectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorTier1 app
 
Best Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh ITBest Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh ITmanoharjgpsolutions
 
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdfEnhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdfRTS corp
 

Dernier (20)

Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
 
2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shards2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shards
 
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
 
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
 
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptxThe Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
 
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
 
Copilot para Microsoft 365 y Power Platform Copilot
Copilot para Microsoft 365 y Power Platform CopilotCopilot para Microsoft 365 y Power Platform Copilot
Copilot para Microsoft 365 y Power Platform Copilot
 
Data modeling 101 - Basics - Software Domain
Data modeling 101 - Basics - Software DomainData modeling 101 - Basics - Software Domain
Data modeling 101 - Basics - Software Domain
 
Introduction to Firebase Workshop Slides
Introduction to Firebase Workshop SlidesIntroduction to Firebase Workshop Slides
Introduction to Firebase Workshop Slides
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and Repair
 
Keeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldKeeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository world
 
VictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News UpdateVictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News Update
 
Zer0con 2024 final share short version.pdf
Zer0con 2024 final share short version.pdfZer0con 2024 final share short version.pdf
Zer0con 2024 final share short version.pdf
 
Amazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilitiesAmazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilities
 
Osi security architecture in network.pptx
Osi security architecture in network.pptxOsi security architecture in network.pptx
Osi security architecture in network.pptx
 
Ronisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited CatalogueRonisha Informatics Private Limited Catalogue
Ronisha Informatics Private Limited Catalogue
 
SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?
 
Effectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorEffectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryError
 
Best Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh ITBest Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh IT
 
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdfEnhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
 

Python for Dummies

  • 4. What is Python or What the hell I am doing here? - Programming Language -Easy to Read -Productive ( ha ha, Java programmer!!) -Portable (.net anyone?) -Big Library ( We got all type of wheels!) ...Fun
  • 5. Created by Guido Van Rossum I am in the same picture, awesome!! This is Guido
  • 8. Python Building Blocks Interpreted Language Compiler Computer
  • 9. Python Building Blocks A language is made by Statements An statement is an order of what You want the computer to do. Examples: Print in the screen the name of the user Create a new windows Calculate age Show Image
  • 10. Python Building Blocks A language is made by Statements An statement is an order of what You want the computer to do. Examples:
  • 11. Python Building Blocks Variable We have to keep track of a lot of information. Examples: "Engineer" 01/27/2013 example@example.com 12,0000
  • 12. Python Building Blocks Variable Reserved Words. and del from not while as elif global or with assert else if pass yield break except import print class exec in raise finally is return continue def for lambda try
  • 14. Python Building Blocks Variables title party_date email debt
  • 15. Python Building Blocks Variables "Engineer" 01/27/2013 e@ex.com 12000 title party_date email debt
  • 16. Python Building Blocks Variables Are Key sensitives: myVariable != MyVariable
  • 17. Python Building Blocks Variables Are Key sensitives: myVariable != MyVariable
  • 18. Python Building Blocks Object Int ex.1234 long ex. 35L float1234 35L 3.1415 bool True False str "Hello World" , 'simply "hello" ' """ Complex strings""" list dict tuple college = [ "awful teachers", "boring books", "some partying"] words_said_by_women_meaning= { "best_friend" : " You lose your chance"} (1, 'other item', 54, 'U')
  • 19. Python Building Blocks -Int Int ex.1234 long ex. 35L float1234 35L 3.1415 Naturals Complex Numbers ( a + bj) Real numbers (a+bj) Basic operations +,-,*,/ , %, ** Compare =, <, >, != Division by integers Division by zero
  • 21. Python Building Blocks Test Pause Work with Variables.py
  • 24. Python Building Blocks -String "Hello World" 0 1 2 3 4 5 6 7 8 9 10
  • 26. Python Building Blocks -String Some useful methods: str.capitalize() str.count(sub[, start[, end]]) str.find(sub, [,start[, end]]) str.index(sub, [,start[, end]]) str.replace(old, mes[,count]) str.lower() / str.upper() str.join(iterable) str.split([sep[,maxsplit]]) Pretty function len(str)
  • 27. Python Building Blocks -Lists A list if a basic structure on python, is defined as : list = [ n1 , n2 , .... nn ] , where N is any basic python data structure
  • 28. Python Building Blocks -Lists A list if a basic structure on python, is defined as : list = [ n1 , n2 , .... nn ] , where N is any basic python data structure training = [ ] Training
  • 29. Python Building Blocks -Lists A list if a basic structure on python, is defined as : list = [ n1 , n2 , .... nn ] , where N is any basic python data structure training = [ ] training.append(50) training.append(60) training.append("Mouse") [0] [1] [2] Training 50 "Mouse" 60
  • 30. Python Building Blocks -Lists A list if a basic structure on python, is defined as : list = [ n1 , n2 , .... nn ] , where N is any basic python data structure training = [ ] training.append(50) training.append(60) training.append("Mouse") [0] [1] [2] Training 50 "Mouse" 60 Index
  • 31. Python Building Blocks -Lists A list if a basic structure on python, is defined as : list = [ n1 , n2 , .... nn ] , where N is any basic python data structure training = [ ] training.append(50) training.append(60) training.append("Mouse") Another way of creating it is: training = [ 50, 60, "Mouse"] [0] [1] [2] Training 50 "Mouse" 60
  • 32. Python Building Blocks -Lists A list if a basic structure on python, is defined as : list = [ n1 , n2 , .... nn ] , where N is any basic python data structure training.extend([3]) [0] [1] [2] [3] Training 50 "Mouse" 60 3
  • 33. Python Building Blocks -Lists A list if a basic structure on python, is defined as : list = [ n1 , n2 , .... nn ] , where N is any basic python data structure training.append(50) [0] [1] [2] [3] [4] Training 50 "Mouse" 60 3 50
  • 34. Python Building Blocks -Lists A list if a basic structure on python, is defined as : list = [ n1 , n2 , .... nn ] , where N is any basic python data structure training.remove(50) [0] [1] [2] [3] Training 50 "Mouse" 60 3
  • 35. Python Building Blocks -Lists A list if a basic structure on python, is defined as : list = [ n1 , n2 , .... nn ] , where N is any basic python data structure training.remove(50) [0] [1] [2] [3] Training 50 "Mouse" 60 3
  • 36. Python Building Blocks -Lists A list if a basic structure on python, is defined as : list = [ n1 , n2 , .... nn ] , where N is any basic python data structure training.pop() [0] [1] [2] Training 50 "Mouse" 60 3
  • 37. Python Building Blocks -Lists A list if a basic structure on python, is defined as : list = [ n1 , n2 , .... nn ] , where N is any basic python data structure training.pop() [0] [1] [2] Training 50 "Mouse" 60 3
  • 38. Python Building Blocks -Lists We treated: list.append(x)* list.extend(L)* list.remove(x)* Other Important functions: list.insert(i, x)* list.pop([i])* list.count(x)* list.sort() list.reverse() *Notes : x: element, i : index, l: list
  • 39. Python Building Blocks -Lists We treated: list.append(x)* list.extend(L)* list.remove(x)* Other Important functions: list.insert(i, x)* list.pop([i])* list.count(x)* list.sort() list.reverse() *Notes : x: element, i : index, l: list
  • 40. Python Building Blocks -Tuples Remember the lists, they are the same but You can't modify them. They are immutable.
  • 41. Python Building Blocks -Tuples Remember the lists, they are the same but You can't modify them. They are immutable. Let's have the immutability talk!
  • 42. Python Building Blocks -Dictionaries Also called Hash or associative Array. Is defined as a collection of references called keys that point to a value. dictionary = { 'key1 ' : value1 , 'key2 ' : value2 , ..................... 'keyN ' : valueN , }
  • 43. Python Building Blocks -Dictionaries Also called Hash or associative Array. Is defined as a collection of references called keys that point to a value. dictionary = { 'key1 ' : value1 , 'key2 ' : value2 , ..................... 'keyN ' : valueN , }
  • 44. Python Building Blocks -Dictionaries Also called Hash or associative Array. Is defined as a collection of references called keys that point to a value. Key Value
  • 45. Python Building Blocks -Dictionaries Also called Hash or associative Array. Is defined as a collection of references called keys that point to a value. You can initialize a Dictionary with the following: d = {} #empty dictionary d = dict()#empty dictionary d = { "hello": "World"} d = dict(hello="world")
  • 46. Python Building Blocks -Dictionaries Some Useful Dictionary methods: len(d) d[key] d[key] = value del d[key] key in d / key not in d d.clear() d.has_key(key) d.keys() d.values() pop(key[, default]) popitem()
  • 47. Python Building Blocks -Other Structures Sets Frozensets Files
  • 48. Python Functions or How to be lazy with style? 1- def goes before the function you are defining. the function name can't be name of another python defined function. 2 - It can have multiple arguments. 4- All functions must have a return value Functions are reusable block codes. def function_name(argument1 , argument2 ,.. .., argumentn ): code block return result 1 2 3 4
  • 49. Python Functions or How to be lazy with style? Some examples:
  • 50. Control Structures, What If...? Conditionals if condition : do something If you have more than one option else comes handy if condition : do something else: do something else
  • 51. Control Structures, What If...? Conditionals When if and else is not enough, maybe you need elif if condition : do something elif: do something different else: do something else
  • 52. Control Structures, What are you waiting for? Conditionals The for is one of the most used control structures example 1: for i in structure : do something with i block example 2: for i in range(n): do something with i block
  • 53. Control Structures, While We wait... Conditionals The while is another control structure used example 1: variable = value while i has condition : do something with i block
  • 54. Control Structures, Other things Somethings of interest Continue: jumps one step Break: break the loop
  • 55. List Comprehension (optional) Somethings of interest [ F(x) for x in object/range + conditional] [F(x1 , x2 , ... xn ) for (x1 , x2 , ... xn ) in object/range(x1 , x2 , ... xn ) + conditional(x1 , x2 , ... xn )]
  • 56. Tuple Comprehension Somethings of interest tuple([ F(x) for x in object/range + conditional]) tuple([F(x1 , x2 , ... xn ) for (x1 , x2 , ... xn ) in object/range(x1 , x2 , ... xn ) + conditional(x1 , x2 , ... xn )])
  • 57. Tuple Comprehension Somethings of interest tuple([ F(x) for x in object/range + conditional]) tuple([F(x1 , x2 , ... xn ) for (x1 , x2 , ... xn ) in object/range(x1 , x2 , ... xn ) + conditional(x1 , x2 , ... xn )])
  • 58. Dictionary Comprehension Somethings of interest { F(x): G(x) for x in object/range + conditional} {F(x1 , x2 , ... xn ):G(x1 , x2 , ... xn ) for (x1 , x2 , ... xn ) in object/range (x1 , x2 , ... xn ) + conditional(x1 , x2 , ... xn )}
  • 59. The Files talk The way Python interacts with files.
  • 60. The Files examples # Open a file fo = open("foo.txt", "wb") print "Name of the file: ", fo.name print "Closed or not : ", fo.closed print "Opening mode : ", fo.mode print "Softspace flag : ", fo.softspace
  • 61. The Files examples class BankAccount(object): def __init__(self, initial_balance=0): self.balance = initial_balance def deposit(self, amount): self.balance += amount def withdraw(self, amount): self.balance -= amount def overdrawn(self): return self.balance < 0 my_account = BankAccount(15) my_account.withdraw(5) print my_account.balance
  • 62. Python Building Blocks -Dir Using "dir": One of the most beautiful functions in Python to study object types.
  • 63. Looking for Help - Exceptions - Dir - Documentation (help) - Documentation (developer) - Stackoverflow.com - IRC - Python Usergroup
  • 64. Python Building Blocks -Int dir is not clear enough, so I made a function Internal Attributes Methods We care
  • 65. Looking for Help - Dir - Documentation (help) - Documentation (developer) - Stackoverflow.com - IRC - Python Usergroup