SlideShare a Scribd company logo
1 of 36
Download to read offline
Introduction to the basics of
Python programming
(PART 1)
by Pedro Rodrigues (pedro@startacareerwithpython.com)
A little about me
 Name: Pedro Rodrigues
 Origin: Luanda (Angola)
 In the Netherlands since 2013
 Former CTO and Senior Backend Engineer
 Freelance Software Engineer
 Book author: Start a Career with Python
 Coach
Why this Meetup Group?
 Promote the usage of Python
 Gather people from different industries and backgrounds
 Teach and Learn
What will be covered
 First steps with the interactive shell: CPython
 Variables and Data types
 Single and Multi variable assignment
 Immutable: strings, tuples, bytes, frozensets
 Mutable: lists, bytearrays, sets, dictionaries
 Control Flow
 if statement
 for statement
 Range, Iterable and Iterators
 while statement
 break and continue
What is Python?
 Dutch product: create by Guido van Rossum in the late 80s
 Interpreted language
 Multi-paradigm: Procedural (imperative), Object Oriented, Functional
 Dynamically Typed
Python interpreter
 CPython: reference, written in C
 PyPy, Jython, IronPython
 help()
 dir()
Hello, world!
Variables
 Binding between a name and an object
 Single variable assignment: x = 1
 Multi variable assignment: x, y = 1, 2
 Swap values: x, y = y, x
Data Types
 Numbers: int (Integers), float (Real Numbers), bool (Boolean, a subset of int)
 Immutable Types: str (string), tuple, bytes, frozenset
 Mutable Types: list, set, bytearray, dict (dictionary)
 Sequence Types: str, tuple, bytes, bytearray, list
 Determining the type of an object: type()
Numbers: int and float
 1 + 2 (addition)
 1 – 2 (subtraction)
 1 * 2 (multiplication)
 1 / 2 (division)
 1 // 2 (integer or floor division)
 3 % 2 (modulus or remainder of the division)
 2**2 (power)
Numbers: bool (continuation)
 1 > 2
 1 < 2
 1 == 2
 Boolean operations: and, or, not
 Objects can also be tested for their truth value. The following values are false:
None, False, zero of any numeric type, empty sequences, empty mapping
str (String)
 x = “This is a string”
 x = ‘This is also a string’
 x = “””So is this one”””
 x = ‘’’And this one as well’’’
 x = “””
This is a string that spans more
than one line. This can also be used
for comments.
“””
str (continuation)
 Indexing elements: x[0] is the first element, x[1] is the second, and so on
 Slicing:
 [start:end:step]
 [start:] # end is the length of the sequence, step assumed to be 1
 [:end] # start is the beginning of the sequence, step assumed to be 1
 [::step] # start is the beginning of the sequence, end is the length
 [start::step]
 [:end:step]
 These operations are common for all sequence types
str (continuation)
 Some common string methods:
 join (concatenates the strings from an iterable using the string as glue)
 format (returns a formatted version of the string)
 strip (returns a copy of the string without leading and trailing whitespace)
 Use help(str.<command>) in the interactive shell and dir(str)
Control Flow (pt. 1): if statement
 Compound statement
if <expression>:
suite
elif <expression2>:
suite
else:
suite
Control Flow (pt. 2): if statement
age = int(input(“> “))
if age >= 30:
print(“You are 30 or above”)
elif 20 < age < 30:
print(“You are in your twenties”)
else:
print(“You are less than 20”)
list
 x = [] # empty list
 x = [1, 2, 3] # list with 3 elements
 x = list(“Hello”)
 x.append(“something”) # append object to the end of the list
 x.insert(2, “something”) # append object before index 2
dict (Dictionaries)
 Mapping between keys and values
 Values can be of whatever type
 Keys must be hashable
 x = {} # empty dictionary
 x = {“Name”: “John”, “Age”: 23}
 x.keys()
 x.values()
 x.items()
Control Flow: for loop
 Also compound statement
 Iterates over the elements of an iterable object
for <target> in <expression>:
suite
else:
suite
Control Flow: for loop (continuation)
colors = [“red”, “green”, “blue”, “orange”]
for color in colors:
print(color)
colors = [[1, “red”], [2, “green”], [3, “blue”], [4, “orange”]]
for i, color in colors:
print(i, “ ---> “, color)
Control Flow: for loop (continuation)
 Iterable is a container object able to return its elements one at a time
 Iterables use iterators to return their elements one at a time
 Iterator is an object that represents a stream of data
 Must implement two methods: __iter__ and __next__ (Iterator protocol)
 Raises StopIteration when elements are exhausted
 Lazy evaluation
Challenge
 Rewrite the following code using enumerate and the following list of colors:
[“red”, “green”, “blue”, “orange”] .
(hint: help(enumerate))
colors = [[1, “red”], [2, “green”], [3, “blue”], [4, “orange”]]
for i, color in colors:
print(i, “ ---> “, color)
Control Flow: for loop (continuation)
 range: represents a sequence of integers
 range(stop)
 range(start, stop)
 range(start, stop, step)
Control Flow: for loop (continuation)
colors = [“red”, “green”, “orange”, “blue”]
for color in colors:
print(color)
else:
print(“Done!”)
Control Flow: while loop
 Executes the suite of statements as long as the expression evaluates to True
while <expression>:
suite
else:
suite
Control Flow: while loop (continuation)
counter = 5
while counter > 0:
print(counter)
counter = counter - 1
counter = 5
while counter > 0:
print(counter)
counter = counter – 1
else:
print(“Done!”)
Challenge
 Rewrite the following code using a for loop and range:
counter = 5
while counter > 0:
print(counter)
counter = counter - 1
Control Flow: break and continue
 Can only occur nested in a for or while loop
 Change the normal flow of execution of a loop:
 break stops the loop
 continue skips to the next iteration
for i in range(10):
if i % 2 == 0:
continue
else:
print(i)
Control Flow: break and (continue)
colors = [“red”, “green”, “blue”, “purple”, “orange”]
for color in colors:
if len(color) > 5:
break
else:
print(color)
Challenge
 Rewrite the following code without the if statement (hint: use the step in range)
for i in range(10):
if i % 2 == 0:
continue
else:
print(i)
Reading material
 Data Model (Python Language Reference):
https://docs.python.org/3/reference/datamodel.html
 The if statement (Python Language Reference):
https://docs.python.org/3/reference/compound_stmts.html#the-if-statement
 The for statement (Python Language Reference):
https://docs.python.org/3/reference/compound_stmts.html#the-for-statement
 The while statement (Python Language Reference):
https://docs.python.org/3/reference/compound_stmts.html#the-while-statement
More resources
 Python Tutorial: https://docs.python.org/3/tutorial/index.html
 Python Language Reference: https://docs.python.org/3/reference/index.html
 Slack channel: https://startcareerpython.slack.com/
 Start a Career with Python newsletter: https://www.startacareerwithpython.com/
 Book 15% off (NZ6SZFBL): https://www.createspace.com/6506874
set
 Unordered mutable collection of elements
 Doesn’t allow duplicate elements
 Elements must be hashable
 Useful to test membership
 x = set() # empty set
 x = {1, 2, 3} # set with 3 integers
 2 in x # membership test
tuple
 x = 1,
 x = (1,)
 x = 1, 2, 3
 x = (1, 2, 3)
 x = (1, “Hello, world!”)
 You can also slice tuples
bytes
 Immutable sequence of bytes
 Each element is an ASCII character
 Integers greater than 127 must be properly escaped
 x = b”This is a bytes object”
 x = b’This is also a bytes object’
 x = b”””So is this”””
 x = b’’’or even this’’’
bytearray
 Mutable counterpart of bytes
 x = bytearray()
 x = bytearray(10)
 x = bytearray(b”Hello, world!”)

More Related Content

What's hot

Introduction to-python
Introduction to-pythonIntroduction to-python
Introduction to-pythonAakashdata
 
Introduction to Python
Introduction to Python Introduction to Python
Introduction to Python amiable_indian
 
Introduction To Python | Edureka
Introduction To Python | EdurekaIntroduction To Python | Edureka
Introduction To Python | EdurekaEdureka!
 
Basic Python Programming: Part 01 and Part 02
Basic Python Programming: Part 01 and Part 02Basic Python Programming: Part 01 and Part 02
Basic Python Programming: Part 01 and Part 02Fariz Darari
 
Python Programming Tutorial | Edureka
Python Programming Tutorial | EdurekaPython Programming Tutorial | Edureka
Python Programming Tutorial | EdurekaEdureka!
 
Python Programming Language | Python Classes | Python Tutorial | Python Train...
Python Programming Language | Python Classes | Python Tutorial | Python Train...Python Programming Language | Python Classes | Python Tutorial | Python Train...
Python Programming Language | Python Classes | Python Tutorial | Python Train...Edureka!
 
Python programming | Fundamentals of Python programming
Python programming | Fundamentals of Python programming Python programming | Fundamentals of Python programming
Python programming | Fundamentals of Python programming KrishnaMildain
 
Let’s Learn Python An introduction to Python
Let’s Learn Python An introduction to Python Let’s Learn Python An introduction to Python
Let’s Learn Python An introduction to Python Jaganadh Gopinadhan
 
Presentation on python
Presentation on pythonPresentation on python
Presentation on pythonwilliam john
 
Python Projects For Beginners | Python Projects Examples | Python Tutorial | ...
Python Projects For Beginners | Python Projects Examples | Python Tutorial | ...Python Projects For Beginners | Python Projects Examples | Python Tutorial | ...
Python Projects For Beginners | Python Projects Examples | Python Tutorial | ...Edureka!
 

What's hot (20)

Introduction to-python
Introduction to-pythonIntroduction to-python
Introduction to-python
 
Introduction to Python
Introduction to Python Introduction to Python
Introduction to Python
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Introduction To Python | Edureka
Introduction To Python | EdurekaIntroduction To Python | Edureka
Introduction To Python | Edureka
 
Python by Rj
Python by RjPython by Rj
Python by Rj
 
Basic Python Programming: Part 01 and Part 02
Basic Python Programming: Part 01 and Part 02Basic Python Programming: Part 01 and Part 02
Basic Python Programming: Part 01 and Part 02
 
Python Tutorial Part 1
Python Tutorial Part 1Python Tutorial Part 1
Python Tutorial Part 1
 
Python Programming Tutorial | Edureka
Python Programming Tutorial | EdurekaPython Programming Tutorial | Edureka
Python Programming Tutorial | Edureka
 
Python basics
Python basicsPython basics
Python basics
 
Python - the basics
Python - the basicsPython - the basics
Python - the basics
 
Python Programming Language | Python Classes | Python Tutorial | Python Train...
Python Programming Language | Python Classes | Python Tutorial | Python Train...Python Programming Language | Python Classes | Python Tutorial | Python Train...
Python Programming Language | Python Classes | Python Tutorial | Python Train...
 
Python basics
Python basicsPython basics
Python basics
 
Python programming | Fundamentals of Python programming
Python programming | Fundamentals of Python programming Python programming | Fundamentals of Python programming
Python programming | Fundamentals of Python programming
 
Let’s Learn Python An introduction to Python
Let’s Learn Python An introduction to Python Let’s Learn Python An introduction to Python
Let’s Learn Python An introduction to Python
 
Programming with Python
Programming with PythonProgramming with Python
Programming with Python
 
Presentation on python
Presentation on pythonPresentation on python
Presentation on python
 
Python basics
Python basicsPython basics
Python basics
 
Intro to Python
Intro to PythonIntro to Python
Intro to Python
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Python Projects For Beginners | Python Projects Examples | Python Tutorial | ...
Python Projects For Beginners | Python Projects Examples | Python Tutorial | ...Python Projects For Beginners | Python Projects Examples | Python Tutorial | ...
Python Projects For Beginners | Python Projects Examples | Python Tutorial | ...
 

Viewers also liked

Basics of Python programming (part 2)
Basics of Python programming (part 2)Basics of Python programming (part 2)
Basics of Python programming (part 2)Pedro Rodrigues
 
Introduction to the basics of Python programming (part 3)
Introduction to the basics of Python programming (part 3)Introduction to the basics of Python programming (part 3)
Introduction to the basics of Python programming (part 3)Pedro Rodrigues
 
Python教程 / Python tutorial
Python教程 / Python tutorialPython教程 / Python tutorial
Python教程 / Python tutorialee0703
 
Python Programming Essentials - M6 - Code Blocks and Indentation
Python Programming Essentials - M6 - Code Blocks and IndentationPython Programming Essentials - M6 - Code Blocks and Indentation
Python Programming Essentials - M6 - Code Blocks and IndentationP3 InfoTech Solutions Pvt. Ltd.
 
AmI 2015 - Python basics
AmI 2015 - Python basicsAmI 2015 - Python basics
AmI 2015 - Python basicsLuigi De Russis
 
AmI 2016 - Python basics
AmI 2016 - Python basicsAmI 2016 - Python basics
AmI 2016 - Python basicsLuigi De Russis
 
Introduction to python programming
Introduction to python programmingIntroduction to python programming
Introduction to python programmingKiran Vadakkath
 
Classification of computers
Classification of computersClassification of computers
Classification of computerssunil kumar
 
Introduction to python 3 2nd round
Introduction to python 3   2nd roundIntroduction to python 3   2nd round
Introduction to python 3 2nd roundYouhei Sakurai
 
Evolution and classification of computers
Evolution and classification of computersEvolution and classification of computers
Evolution and classification of computersAVINASH ANAND
 

Viewers also liked (20)

Python tutorial
Python tutorialPython tutorial
Python tutorial
 
Basics of Python programming (part 2)
Basics of Python programming (part 2)Basics of Python programming (part 2)
Basics of Python programming (part 2)
 
Introduction to the basics of Python programming (part 3)
Introduction to the basics of Python programming (part 3)Introduction to the basics of Python programming (part 3)
Introduction to the basics of Python programming (part 3)
 
Python教程 / Python tutorial
Python教程 / Python tutorialPython教程 / Python tutorial
Python教程 / Python tutorial
 
Python Tutorial Part 2
Python Tutorial Part 2Python Tutorial Part 2
Python Tutorial Part 2
 
Python - basics
Python - basicsPython - basics
Python - basics
 
PythonIntro
PythonIntroPythonIntro
PythonIntro
 
Python Tutorial
Python TutorialPython Tutorial
Python Tutorial
 
Python Programming Essentials - M6 - Code Blocks and Indentation
Python Programming Essentials - M6 - Code Blocks and IndentationPython Programming Essentials - M6 - Code Blocks and Indentation
Python Programming Essentials - M6 - Code Blocks and Indentation
 
AmI 2015 - Python basics
AmI 2015 - Python basicsAmI 2015 - Python basics
AmI 2015 - Python basics
 
Python Basics
Python BasicsPython Basics
Python Basics
 
Python Workshop
Python WorkshopPython Workshop
Python Workshop
 
python codes
python codespython codes
python codes
 
AmI 2016 - Python basics
AmI 2016 - Python basicsAmI 2016 - Python basics
AmI 2016 - Python basics
 
Introduction to python programming
Introduction to python programmingIntroduction to python programming
Introduction to python programming
 
Python basics
Python basicsPython basics
Python basics
 
Classification of computers
Classification of computersClassification of computers
Classification of computers
 
Introduction to python 3 2nd round
Introduction to python 3   2nd roundIntroduction to python 3   2nd round
Introduction to python 3 2nd round
 
Evolution and classification of computers
Evolution and classification of computersEvolution and classification of computers
Evolution and classification of computers
 
Python programming language
Python programming languagePython programming language
Python programming language
 

Similar to Introduction to the basics of Python programming (part 1)

introductionpart1-160906115340 (1).pptx
introductionpart1-160906115340 (1).pptxintroductionpart1-160906115340 (1).pptx
introductionpart1-160906115340 (1).pptxAsthaChaurasia4
 
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
 
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...DRVaibhavmeshram1
 
PythonStudyMaterialSTudyMaterial.pdf
PythonStudyMaterialSTudyMaterial.pdfPythonStudyMaterialSTudyMaterial.pdf
PythonStudyMaterialSTudyMaterial.pdfdata2businessinsight
 
ISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docx
ISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docxISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docx
ISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docxpriestmanmable
 
Python-CH01L04-Presentation.pptx
Python-CH01L04-Presentation.pptxPython-CH01L04-Presentation.pptx
Python-CH01L04-Presentation.pptxElijahSantos4
 
Automation Testing theory notes.pptx
Automation Testing theory notes.pptxAutomation Testing theory notes.pptx
Automation Testing theory notes.pptxNileshBorkar12
 
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
 
Python interview questions and answers
Python interview questions and answersPython interview questions and answers
Python interview questions and answersRojaPriya
 
Python: an introduction for PHP webdevelopers
Python: an introduction for PHP webdevelopersPython: an introduction for PHP webdevelopers
Python: an introduction for PHP webdevelopersGlenn De Backer
 
Python introduction
Python introductionPython introduction
Python introductionleela rani
 
01-Python-Basics.ppt
01-Python-Basics.ppt01-Python-Basics.ppt
01-Python-Basics.pptVicVic56
 
Python interview questions and answers
Python interview questions and answersPython interview questions and answers
Python interview questions and answerskavinilavuG
 
Basic of Python- Hands on Session
Basic of Python- Hands on SessionBasic of Python- Hands on Session
Basic of Python- Hands on SessionDharmesh Tank
 

Similar to Introduction to the basics of Python programming (part 1) (20)

introductionpart1-160906115340 (1).pptx
introductionpart1-160906115340 (1).pptxintroductionpart1-160906115340 (1).pptx
introductionpart1-160906115340 (1).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 for Beginners(v1)
Python for Beginners(v1)Python for Beginners(v1)
Python for Beginners(v1)
 
Python basics
Python basicsPython basics
Python basics
 
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
Introduction to Python 01-08-2023.pon by everyone else. . Hence, they must be...
 
PythonStudyMaterialSTudyMaterial.pdf
PythonStudyMaterialSTudyMaterial.pdfPythonStudyMaterialSTudyMaterial.pdf
PythonStudyMaterialSTudyMaterial.pdf
 
ISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docx
ISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docxISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docx
ISTA 130 Lab 21 Turtle ReviewHere are all of the turt.docx
 
Python-CH01L04-Presentation.pptx
Python-CH01L04-Presentation.pptxPython-CH01L04-Presentation.pptx
Python-CH01L04-Presentation.pptx
 
Automation Testing theory notes.pptx
Automation Testing theory notes.pptxAutomation Testing theory notes.pptx
Automation Testing theory notes.pptx
 
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 ...
 
Biopython: Overview, State of the Art and Outlook
Biopython: Overview, State of the Art and OutlookBiopython: Overview, State of the Art and Outlook
Biopython: Overview, State of the Art and Outlook
 
Python interview questions and answers
Python interview questions and answersPython interview questions and answers
Python interview questions and answers
 
Python: an introduction for PHP webdevelopers
Python: an introduction for PHP webdevelopersPython: an introduction for PHP webdevelopers
Python: an introduction for PHP webdevelopers
 
Python introduction
Python introductionPython introduction
Python introduction
 
01-Python-Basics.ppt
01-Python-Basics.ppt01-Python-Basics.ppt
01-Python-Basics.ppt
 
Python interview questions and answers
Python interview questions and answersPython interview questions and answers
Python interview questions and answers
 
python
pythonpython
python
 
Python 3.pptx
Python 3.pptxPython 3.pptx
Python 3.pptx
 
Basic of Python- Hands on Session
Basic of Python- Hands on SessionBasic of Python- Hands on Session
Basic of Python- Hands on Session
 
Computation Chapter 4
Computation Chapter 4Computation Chapter 4
Computation Chapter 4
 

Recently uploaded

What’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 UpdatesWhat’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 UpdatesVictoriaMetrics
 
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
 
[ CNCF Q1 2024 ] Intro to Continuous Profiling and Grafana Pyroscope.pdf
[ CNCF Q1 2024 ] Intro to Continuous Profiling and Grafana Pyroscope.pdf[ CNCF Q1 2024 ] Intro to Continuous Profiling and Grafana Pyroscope.pdf
[ CNCF Q1 2024 ] Intro to Continuous Profiling and Grafana Pyroscope.pdfSteve Caron
 
Introduction to Firebase Workshop Slides
Introduction to Firebase Workshop SlidesIntroduction to Firebase Workshop Slides
Introduction to Firebase Workshop Slidesvaideheekore1
 
The Ultimate Guide to Performance Testing in Low-Code, No-Code Environments (...
The Ultimate Guide to Performance Testing in Low-Code, No-Code Environments (...The Ultimate Guide to Performance Testing in Low-Code, No-Code Environments (...
The Ultimate Guide to Performance Testing in Low-Code, No-Code Environments (...kalichargn70th171
 
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
 
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
 
Advantages of Cargo Cloud Solutions.pptx
Advantages of Cargo Cloud Solutions.pptxAdvantages of Cargo Cloud Solutions.pptx
Advantages of Cargo Cloud Solutions.pptxRTS corp
 
Understanding Plagiarism: Causes, Consequences and Prevention.pptx
Understanding Plagiarism: Causes, Consequences and Prevention.pptxUnderstanding Plagiarism: Causes, Consequences and Prevention.pptx
Understanding Plagiarism: Causes, Consequences and Prevention.pptxSasikiranMarri
 
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingOpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingShane Coughlan
 
Effectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorEffectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorTier1 app
 
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
 
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
 
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
 
Pros and Cons of Selenium In Automation Testing_ A Comprehensive Assessment.pdf
Pros and Cons of Selenium In Automation Testing_ A Comprehensive Assessment.pdfPros and Cons of Selenium In Automation Testing_ A Comprehensive Assessment.pdf
Pros and Cons of Selenium In Automation Testing_ A Comprehensive Assessment.pdfkalichargn70th171
 
Key Steps in Agile Software Delivery Roadmap
Key Steps in Agile Software Delivery RoadmapKey Steps in Agile Software Delivery Roadmap
Key Steps in Agile Software Delivery RoadmapIshara Amarasekera
 
Effort Estimation Techniques used in Software Projects
Effort Estimation Techniques used in Software ProjectsEffort Estimation Techniques used in Software Projects
Effort Estimation Techniques used in Software ProjectsDEEPRAJ PATHAK
 
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
 
GraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4j
GraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4jGraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4j
GraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4jNeo4j
 
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
 

Recently uploaded (20)

What’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 UpdatesWhat’s New in VictoriaMetrics: Q1 2024 Updates
What’s New in VictoriaMetrics: Q1 2024 Updates
 
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
 
[ CNCF Q1 2024 ] Intro to Continuous Profiling and Grafana Pyroscope.pdf
[ CNCF Q1 2024 ] Intro to Continuous Profiling and Grafana Pyroscope.pdf[ CNCF Q1 2024 ] Intro to Continuous Profiling and Grafana Pyroscope.pdf
[ CNCF Q1 2024 ] Intro to Continuous Profiling and Grafana Pyroscope.pdf
 
Introduction to Firebase Workshop Slides
Introduction to Firebase Workshop SlidesIntroduction to Firebase Workshop Slides
Introduction to Firebase Workshop Slides
 
The Ultimate Guide to Performance Testing in Low-Code, No-Code Environments (...
The Ultimate Guide to Performance Testing in Low-Code, No-Code Environments (...The Ultimate Guide to Performance Testing in Low-Code, No-Code Environments (...
The Ultimate Guide to Performance Testing in Low-Code, No-Code Environments (...
 
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...
 
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
 
Advantages of Cargo Cloud Solutions.pptx
Advantages of Cargo Cloud Solutions.pptxAdvantages of Cargo Cloud Solutions.pptx
Advantages of Cargo Cloud Solutions.pptx
 
Understanding Plagiarism: Causes, Consequences and Prevention.pptx
Understanding Plagiarism: Causes, Consequences and Prevention.pptxUnderstanding Plagiarism: Causes, Consequences and Prevention.pptx
Understanding Plagiarism: Causes, Consequences and Prevention.pptx
 
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingOpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
 
Effectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorEffectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryError
 
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
 
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 ...
 
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...
 
Pros and Cons of Selenium In Automation Testing_ A Comprehensive Assessment.pdf
Pros and Cons of Selenium In Automation Testing_ A Comprehensive Assessment.pdfPros and Cons of Selenium In Automation Testing_ A Comprehensive Assessment.pdf
Pros and Cons of Selenium In Automation Testing_ A Comprehensive Assessment.pdf
 
Key Steps in Agile Software Delivery Roadmap
Key Steps in Agile Software Delivery RoadmapKey Steps in Agile Software Delivery Roadmap
Key Steps in Agile Software Delivery Roadmap
 
Effort Estimation Techniques used in Software Projects
Effort Estimation Techniques used in Software ProjectsEffort Estimation Techniques used in Software Projects
Effort Estimation Techniques used in Software Projects
 
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 ?
 
GraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4j
GraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4jGraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4j
GraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4j
 
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
 

Introduction to the basics of Python programming (part 1)

  • 1. Introduction to the basics of Python programming (PART 1) by Pedro Rodrigues (pedro@startacareerwithpython.com)
  • 2. A little about me  Name: Pedro Rodrigues  Origin: Luanda (Angola)  In the Netherlands since 2013  Former CTO and Senior Backend Engineer  Freelance Software Engineer  Book author: Start a Career with Python  Coach
  • 3. Why this Meetup Group?  Promote the usage of Python  Gather people from different industries and backgrounds  Teach and Learn
  • 4. What will be covered  First steps with the interactive shell: CPython  Variables and Data types  Single and Multi variable assignment  Immutable: strings, tuples, bytes, frozensets  Mutable: lists, bytearrays, sets, dictionaries  Control Flow  if statement  for statement  Range, Iterable and Iterators  while statement  break and continue
  • 5. What is Python?  Dutch product: create by Guido van Rossum in the late 80s  Interpreted language  Multi-paradigm: Procedural (imperative), Object Oriented, Functional  Dynamically Typed
  • 6. Python interpreter  CPython: reference, written in C  PyPy, Jython, IronPython  help()  dir()
  • 8. Variables  Binding between a name and an object  Single variable assignment: x = 1  Multi variable assignment: x, y = 1, 2  Swap values: x, y = y, x
  • 9. Data Types  Numbers: int (Integers), float (Real Numbers), bool (Boolean, a subset of int)  Immutable Types: str (string), tuple, bytes, frozenset  Mutable Types: list, set, bytearray, dict (dictionary)  Sequence Types: str, tuple, bytes, bytearray, list  Determining the type of an object: type()
  • 10. Numbers: int and float  1 + 2 (addition)  1 – 2 (subtraction)  1 * 2 (multiplication)  1 / 2 (division)  1 // 2 (integer or floor division)  3 % 2 (modulus or remainder of the division)  2**2 (power)
  • 11. Numbers: bool (continuation)  1 > 2  1 < 2  1 == 2  Boolean operations: and, or, not  Objects can also be tested for their truth value. The following values are false: None, False, zero of any numeric type, empty sequences, empty mapping
  • 12. str (String)  x = “This is a string”  x = ‘This is also a string’  x = “””So is this one”””  x = ‘’’And this one as well’’’  x = “”” This is a string that spans more than one line. This can also be used for comments. “””
  • 13. str (continuation)  Indexing elements: x[0] is the first element, x[1] is the second, and so on  Slicing:  [start:end:step]  [start:] # end is the length of the sequence, step assumed to be 1  [:end] # start is the beginning of the sequence, step assumed to be 1  [::step] # start is the beginning of the sequence, end is the length  [start::step]  [:end:step]  These operations are common for all sequence types
  • 14. str (continuation)  Some common string methods:  join (concatenates the strings from an iterable using the string as glue)  format (returns a formatted version of the string)  strip (returns a copy of the string without leading and trailing whitespace)  Use help(str.<command>) in the interactive shell and dir(str)
  • 15. Control Flow (pt. 1): if statement  Compound statement if <expression>: suite elif <expression2>: suite else: suite
  • 16. Control Flow (pt. 2): if statement age = int(input(“> “)) if age >= 30: print(“You are 30 or above”) elif 20 < age < 30: print(“You are in your twenties”) else: print(“You are less than 20”)
  • 17. list  x = [] # empty list  x = [1, 2, 3] # list with 3 elements  x = list(“Hello”)  x.append(“something”) # append object to the end of the list  x.insert(2, “something”) # append object before index 2
  • 18. dict (Dictionaries)  Mapping between keys and values  Values can be of whatever type  Keys must be hashable  x = {} # empty dictionary  x = {“Name”: “John”, “Age”: 23}  x.keys()  x.values()  x.items()
  • 19. Control Flow: for loop  Also compound statement  Iterates over the elements of an iterable object for <target> in <expression>: suite else: suite
  • 20. Control Flow: for loop (continuation) colors = [“red”, “green”, “blue”, “orange”] for color in colors: print(color) colors = [[1, “red”], [2, “green”], [3, “blue”], [4, “orange”]] for i, color in colors: print(i, “ ---> “, color)
  • 21. Control Flow: for loop (continuation)  Iterable is a container object able to return its elements one at a time  Iterables use iterators to return their elements one at a time  Iterator is an object that represents a stream of data  Must implement two methods: __iter__ and __next__ (Iterator protocol)  Raises StopIteration when elements are exhausted  Lazy evaluation
  • 22. Challenge  Rewrite the following code using enumerate and the following list of colors: [“red”, “green”, “blue”, “orange”] . (hint: help(enumerate)) colors = [[1, “red”], [2, “green”], [3, “blue”], [4, “orange”]] for i, color in colors: print(i, “ ---> “, color)
  • 23. Control Flow: for loop (continuation)  range: represents a sequence of integers  range(stop)  range(start, stop)  range(start, stop, step)
  • 24. Control Flow: for loop (continuation) colors = [“red”, “green”, “orange”, “blue”] for color in colors: print(color) else: print(“Done!”)
  • 25. Control Flow: while loop  Executes the suite of statements as long as the expression evaluates to True while <expression>: suite else: suite
  • 26. Control Flow: while loop (continuation) counter = 5 while counter > 0: print(counter) counter = counter - 1 counter = 5 while counter > 0: print(counter) counter = counter – 1 else: print(“Done!”)
  • 27. Challenge  Rewrite the following code using a for loop and range: counter = 5 while counter > 0: print(counter) counter = counter - 1
  • 28. Control Flow: break and continue  Can only occur nested in a for or while loop  Change the normal flow of execution of a loop:  break stops the loop  continue skips to the next iteration for i in range(10): if i % 2 == 0: continue else: print(i)
  • 29. Control Flow: break and (continue) colors = [“red”, “green”, “blue”, “purple”, “orange”] for color in colors: if len(color) > 5: break else: print(color)
  • 30. Challenge  Rewrite the following code without the if statement (hint: use the step in range) for i in range(10): if i % 2 == 0: continue else: print(i)
  • 31. Reading material  Data Model (Python Language Reference): https://docs.python.org/3/reference/datamodel.html  The if statement (Python Language Reference): https://docs.python.org/3/reference/compound_stmts.html#the-if-statement  The for statement (Python Language Reference): https://docs.python.org/3/reference/compound_stmts.html#the-for-statement  The while statement (Python Language Reference): https://docs.python.org/3/reference/compound_stmts.html#the-while-statement
  • 32. More resources  Python Tutorial: https://docs.python.org/3/tutorial/index.html  Python Language Reference: https://docs.python.org/3/reference/index.html  Slack channel: https://startcareerpython.slack.com/  Start a Career with Python newsletter: https://www.startacareerwithpython.com/  Book 15% off (NZ6SZFBL): https://www.createspace.com/6506874
  • 33. set  Unordered mutable collection of elements  Doesn’t allow duplicate elements  Elements must be hashable  Useful to test membership  x = set() # empty set  x = {1, 2, 3} # set with 3 integers  2 in x # membership test
  • 34. tuple  x = 1,  x = (1,)  x = 1, 2, 3  x = (1, 2, 3)  x = (1, “Hello, world!”)  You can also slice tuples
  • 35. bytes  Immutable sequence of bytes  Each element is an ASCII character  Integers greater than 127 must be properly escaped  x = b”This is a bytes object”  x = b’This is also a bytes object’  x = b”””So is this”””  x = b’’’or even this’’’
  • 36. bytearray  Mutable counterpart of bytes  x = bytearray()  x = bytearray(10)  x = bytearray(b”Hello, world!”)