SlideShare a Scribd company logo
1 of 21
Download to read offline
What is new in Python 3.9
Haim Michael
March 8th
, 2021
All logos, trade marks and brand names used in this presentation belong
to the respective owners.
life
michae
l
Let's be on The Edge
www.lifemichael.com
© 2008 Haim Michael 20150805
Python 3.9
© 2008 Haim Michael 20150805
The dict Union | Operator
 The dict union operator | return a new dict consisting of the
left operand merged with the right operand, each of which
must be a dict (or an instance of a dict subclass).
 When the key appears in both operands, the last-seen value
(i.e. that from the right-hand operand) wins.
https://www.python.org/dev/peps/pep-0584/
© 2008 Haim Michael 20150805
The dict Union | Operator
dict1 = {1:'one', 2:'two', 3:'three'}
dict2 = {3:'three',4:'four',5:'five',6:'six'}
dict3 = dict1 | dict2
print(dict3)
© 2008 Haim Michael 20150805
Type Hinting Generics in Collections
 We can now use the generics syntax when using the standard
collections in Python. We are no longer limited to using
generics with the collections the typing module includes.
 As of Python 3.9 we no longer need the standard collections
the typing module includes.
https://www.python.org/dev/peps/pep-0585/
© 2008 Haim Michael 20150805
Type Hinting Generics in Collections
numbers: list[int] = [23, 3, 6]
student: tuple[str, str, float, int] = ("mosh", "solomon", 98.2, 2343243)
nicknames: dict[str, str] = {"mosh": "moshe", "tal": "talia", "avi": "avraham"}
winners: set[str] = {"dave", "mark", "tal", "doron", "jane"}
print(numbers)
print(student)
print(nicknames)
print(winners)
© 2008 Haim Michael 20150805
The Prefix and Suffix Methods
 The methods, removeprefix() and removesuffix(), are
now available when using Python's various string objects.
 These methods would remove a prefix or suffix (respectively)
from a string, if present.
 These two methods will be available when using objects of the
types str, bytes, bytearray and collections.UserString.
https://www.python.org/dev/peps/pep-0616/
© 2008 Haim Michael 20150805
The Prefix and Suffix Methods
filenames:list[str] = [
"king.txt.txt",
"temp.txt",
"pep8song.txt",
"data.txt"]
for filename in filenames:
if filename.endswith(".txt.txt"):
print(filename.removesuffix(".txt"))
else:
print(filename)
© 2008 Haim Michael 20150805
The Prefix and Suffix Methods
names: list[str] = ["Dr.Mosh Levin", "Dr.Ronan Cohen", "Ran Roze"]
for name in names:
if name.startswith("Dr."):
print(name.removeprefix("Dr."))
else:
print(name)
© 2008 Haim Michael 20150805
Annotated Type Hints
 The possibility to annotate a function allows us to add
arbitrary metadata to functions we define.
def calc(distance: "meter", time: "second") -> "km per hour":
return 3600 * (distance / 1000) / time
 As of Python 3.9 we can use the typing.Annotated
from typing import Annotated
def calc(
distance: Annotated[int, "meter"],
time: Annotated[float, "second"]
) -> Annotated[float, "km per hour"]:
return 3600 * (distance / 1000) / time
© 2008 Haim Michael 20150805
Annotated Type Hints
 We can (as usual) access the annotations through
the .__annotations__ attribute.
from typing import Annotated
def calc(
distance: Annotated[int, "meter"],
time: Annotated[float, "second"]
) -> Annotated[float, "km per hour"]:
return 3600 * (distance / 1000) / time
print(calc.__annotations__)
© 2008 Haim Michael 20150805
Annotated Type Hints
 We can keep our code more readable by using type
aliases.
from typing import Annotated
Meter = Annotated[int, "meter"]
Second = Annotated[int, "second"]
KmPerHour = Annotated[float, "km per hour"]
def calc(distance: Meter, time: Second) -> KmPerHour:
return 3600 * (distance / 1000) / time
print(calc.__annotations__)
© 2008 Haim Michael 20150805
Powerful Parser
 One of the main components of the Python interpreter
is the parser.
 As of Python 3.9, we have a new parser. The new
parser was developed based on Guido's research of
PEG (Parsing Expression Grammar) parsers.
© 2008 Haim Michael 20150805
Powerful Parser
 The interpreter (in Python 3.9) includes both the new
PEG parser and the old LL(1) parser. The PEG parser
is the default one. It is still possible to use the LL(1) old
one by using the -X oldparser command-line flag:
$ python -X oldparser program.py
© 2008 Haim Michael 20150805
Powerful Parser
 The old parser will be removed in Python 3.10. This will
allow the implementation of new features without the
limitations of an LL(1) grammar (e.g. implementing
structural pattern matching).
 The performance of both parsers, the PEG parser and
the LL(1) parser, is similar.
© 2008 Haim Michael 20150805
The graphlib Module
 As of Python 3.9, the standard library includes the
graphlib new module.
from graphlib import TopologicalSorter
dependencies = {
"Java EE": {"Java", "Angular"},
"Angular": {"JavaScript"},
"Java": {"C++", "SQL"},
"C++": {"C"}
}
sorter = TopologicalSorter(dependencies)
print(list(sorter.static_order()))
© 2008 Haim Michael 20150805
The Least Common Multiple(LCM)
 As of Python 3.9, we can easily find the least common
multiple (LCM) by calling the math.lcm function.
import math
num1 = 5
num2 = 7
num3 = 3
result = math.lcm(num1,num2,num3)
print(result)
© 2008 Haim Michael 20150805
HTTP Status Codes
 As of Python 3.9, the http module includes two more
status codes: 103 (Early Hints) and 425 (Too Early).
from http import HTTPStatus
print(HTTPStatus.OK)
print(HTTPStatus.OK.description)
print(HTTPStatus.OK.value)
print(HTTPStatus.OK.phrase)
print(HTTPStatus.NOT_FOUND)
print(HTTPStatus.NOT_FOUND.description)
print(HTTPStatus.NOT_FOUND.value)
print(HTTPStatus.NOT_FOUND.phrase)
print(HTTPStatus.EARLY_HINTS)
print(HTTPStatus.TOO_EARLY)
© 2008 Haim Michael 20150805
The zoneinfo Module
 The zoneinfo was added in Python 3.9. It
complements the datetime module by allowing us
getting information about the time zone.
from datetime import datetime
from zoneinfo import ZoneInfo
vancouver = ZoneInfo("America/Vancouver")
release = datetime(2020, 11, 25, 2, 12, tzinfo=vancouver)
print(release)
© 2008 Haim Michael 20150805
The zoneinfo Module
 The following code sample prints out the available time
zones.
import zoneinfo
zones = zoneinfo.available_timezones()
print(len(zones))
print(zones)
© 2009 Haim Michael All Rights Reserved 21
Questions & Answers
Thanks for Your Time!
Haim Michael
haim.michael@lifemichael.com
+972+3+3726013 ext:700
+972+54+6655837 (whatsapp)
life
michael

More Related Content

What's hot

Functional and Algebraic Domain Modeling
Functional and Algebraic Domain ModelingFunctional and Algebraic Domain Modeling
Functional and Algebraic Domain ModelingDebasish Ghosh
 
Php Error Handling
Php Error HandlingPhp Error Handling
Php Error Handlingmussawir20
 
Chapter25
Chapter25Chapter25
Chapter25inddxp
 
Surveillance System (Minimum Vertex Cover Problem)
Surveillance System (Minimum Vertex Cover Problem) Surveillance System (Minimum Vertex Cover Problem)
Surveillance System (Minimum Vertex Cover Problem) Saksham Saxena
 
Embedding Web UIs in your Eclipse application
Embedding Web UIs in your Eclipse applicationEmbedding Web UIs in your Eclipse application
Embedding Web UIs in your Eclipse applicationBoris Bokowski
 
String Matching with Finite Automata,Aho corasick,
String Matching with Finite Automata,Aho corasick,String Matching with Finite Automata,Aho corasick,
String Matching with Finite Automata,Aho corasick,8neutron8
 
Theory of Computation "Chapter 1, introduction"
Theory of Computation "Chapter 1, introduction"Theory of Computation "Chapter 1, introduction"
Theory of Computation "Chapter 1, introduction"Ra'Fat Al-Msie'deen
 
Ch3 4 regular expression and grammar
Ch3 4 regular expression and grammarCh3 4 regular expression and grammar
Ch3 4 regular expression and grammarmeresie tesfay
 
How to write a TableGen backend
How to write a TableGen backendHow to write a TableGen backend
How to write a TableGen backendMin-Yih Hsu
 
The SAM Pattern: State Machines and Computation
The SAM Pattern: State Machines and ComputationThe SAM Pattern: State Machines and Computation
The SAM Pattern: State Machines and ComputationJean-Jacques Dubray
 
Librerias java
Librerias javaLibrerias java
Librerias javaDaniel Val
 

What's hot (20)

Functional and Algebraic Domain Modeling
Functional and Algebraic Domain ModelingFunctional and Algebraic Domain Modeling
Functional and Algebraic Domain Modeling
 
Kruskal Algorithm
Kruskal AlgorithmKruskal Algorithm
Kruskal Algorithm
 
Php Error Handling
Php Error HandlingPhp Error Handling
Php Error Handling
 
Chapter25
Chapter25Chapter25
Chapter25
 
Surveillance System (Minimum Vertex Cover Problem)
Surveillance System (Minimum Vertex Cover Problem) Surveillance System (Minimum Vertex Cover Problem)
Surveillance System (Minimum Vertex Cover Problem)
 
Embedding Web UIs in your Eclipse application
Embedding Web UIs in your Eclipse applicationEmbedding Web UIs in your Eclipse application
Embedding Web UIs in your Eclipse application
 
MySQL Cheat Sheet
MySQL Cheat SheetMySQL Cheat Sheet
MySQL Cheat Sheet
 
String Matching with Finite Automata,Aho corasick,
String Matching with Finite Automata,Aho corasick,String Matching with Finite Automata,Aho corasick,
String Matching with Finite Automata,Aho corasick,
 
EIP with Apache Camel
EIP with Apache CamelEIP with Apache Camel
EIP with Apache Camel
 
ZIO Queue
ZIO QueueZIO Queue
ZIO Queue
 
Java Swing
Java SwingJava Swing
Java Swing
 
Theory of Computation "Chapter 1, introduction"
Theory of Computation "Chapter 1, introduction"Theory of Computation "Chapter 1, introduction"
Theory of Computation "Chapter 1, introduction"
 
DBMS 4 | MySQL - DDL & DML Commands
DBMS 4 | MySQL - DDL & DML CommandsDBMS 4 | MySQL - DDL & DML Commands
DBMS 4 | MySQL - DDL & DML Commands
 
Ch3 4 regular expression and grammar
Ch3 4 regular expression and grammarCh3 4 regular expression and grammar
Ch3 4 regular expression and grammar
 
String matching, naive,
String matching, naive,String matching, naive,
String matching, naive,
 
How to write a TableGen backend
How to write a TableGen backendHow to write a TableGen backend
How to write a TableGen backend
 
SQL.ppt
SQL.pptSQL.ppt
SQL.ppt
 
L3 cfg
L3 cfgL3 cfg
L3 cfg
 
The SAM Pattern: State Machines and Computation
The SAM Pattern: State Machines and ComputationThe SAM Pattern: State Machines and Computation
The SAM Pattern: State Machines and Computation
 
Librerias java
Librerias javaLibrerias java
Librerias java
 

Similar to What is new in Python 3.9

Stata cheatsheet programming
Stata cheatsheet programmingStata cheatsheet programming
Stata cheatsheet programmingTim Essam
 
Stata Programming Cheat Sheet
Stata Programming Cheat SheetStata Programming Cheat Sheet
Stata Programming Cheat SheetLaura Hughes
 
Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Python Functions Tutorial | Working With Functions In Python | Python Trainin...Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Python Functions Tutorial | Working With Functions In Python | Python Trainin...Edureka!
 
Introduction to new features in java 8
Introduction to new features in java 8Introduction to new features in java 8
Introduction to new features in java 8Raffi Khatchadourian
 
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
 
What is new in PHP
What is new in PHPWhat is new in PHP
What is new in PHPHaim Michael
 
COMM 166 Final Research Proposal GuidelinesThe proposal should.docx
COMM 166 Final Research Proposal GuidelinesThe proposal should.docxCOMM 166 Final Research Proposal GuidelinesThe proposal should.docx
COMM 166 Final Research Proposal GuidelinesThe proposal should.docxmonicafrancis71118
 
COMM 166 Final Research Proposal GuidelinesThe proposal should.docx
COMM 166 Final Research Proposal GuidelinesThe proposal should.docxCOMM 166 Final Research Proposal GuidelinesThe proposal should.docx
COMM 166 Final Research Proposal GuidelinesThe proposal should.docxcargillfilberto
 
COMM 166 Final Research Proposal GuidelinesThe proposal should.docx
COMM 166 Final Research Proposal GuidelinesThe proposal should.docxCOMM 166 Final Research Proposal GuidelinesThe proposal should.docx
COMM 166 Final Research Proposal GuidelinesThe proposal should.docxdrandy1
 
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
 
Python Evolution
Python EvolutionPython Evolution
Python EvolutionQuintagroup
 
Apache Flink: API, runtime, and project roadmap
Apache Flink: API, runtime, and project roadmapApache Flink: API, runtime, and project roadmap
Apache Flink: API, runtime, and project roadmapKostas Tzoumas
 
The num py_library_20200818
The num py_library_20200818The num py_library_20200818
The num py_library_20200818Haim Michael
 
QTP Automation Testing Tutorial 7
QTP Automation Testing Tutorial 7QTP Automation Testing Tutorial 7
QTP Automation Testing Tutorial 7Akash Tyagi
 

Similar to What is new in Python 3.9 (20)

Stata cheatsheet programming
Stata cheatsheet programmingStata cheatsheet programming
Stata cheatsheet programming
 
Stata Programming Cheat Sheet
Stata Programming Cheat SheetStata Programming Cheat Sheet
Stata Programming Cheat Sheet
 
Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Python Functions Tutorial | Working With Functions In Python | Python Trainin...Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Python Functions Tutorial | Working With Functions In Python | Python Trainin...
 
Introduction to new features in java 8
Introduction to new features in java 8Introduction to new features in java 8
Introduction to new features in java 8
 
Introduction to new features in java 8
Introduction to new features in java 8Introduction to new features in java 8
Introduction to new features in java 8
 
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
 
What is new in PHP
What is new in PHPWhat is new in PHP
What is new in PHP
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
Ds lab handouts
Ds lab handoutsDs lab handouts
Ds lab handouts
 
Matlab Manual
Matlab ManualMatlab Manual
Matlab Manual
 
COMM 166 Final Research Proposal GuidelinesThe proposal should.docx
COMM 166 Final Research Proposal GuidelinesThe proposal should.docxCOMM 166 Final Research Proposal GuidelinesThe proposal should.docx
COMM 166 Final Research Proposal GuidelinesThe proposal should.docx
 
COMM 166 Final Research Proposal GuidelinesThe proposal should.docx
COMM 166 Final Research Proposal GuidelinesThe proposal should.docxCOMM 166 Final Research Proposal GuidelinesThe proposal should.docx
COMM 166 Final Research Proposal GuidelinesThe proposal should.docx
 
COMM 166 Final Research Proposal GuidelinesThe proposal should.docx
COMM 166 Final Research Proposal GuidelinesThe proposal should.docxCOMM 166 Final Research Proposal GuidelinesThe proposal should.docx
COMM 166 Final Research Proposal GuidelinesThe proposal should.docx
 
Python cheat-sheet
Python cheat-sheetPython cheat-sheet
Python cheat-sheet
 
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
 
Python Evolution
Python EvolutionPython Evolution
Python Evolution
 
Apache Flink: API, runtime, and project roadmap
Apache Flink: API, runtime, and project roadmapApache Flink: API, runtime, and project roadmap
Apache Flink: API, runtime, and project roadmap
 
The num py_library_20200818
The num py_library_20200818The num py_library_20200818
The num py_library_20200818
 
QTP Automation Testing Tutorial 7
QTP Automation Testing Tutorial 7QTP Automation Testing Tutorial 7
QTP Automation Testing Tutorial 7
 

More from Haim Michael

Virtual Threads in Java
Virtual Threads in JavaVirtual Threads in Java
Virtual Threads in JavaHaim Michael
 
MongoDB Design Patterns
MongoDB Design PatternsMongoDB Design Patterns
MongoDB Design PatternsHaim Michael
 
Introduction to SQL Injections
Introduction to SQL InjectionsIntroduction to SQL Injections
Introduction to SQL InjectionsHaim Michael
 
Record Classes in Java
Record Classes in JavaRecord Classes in Java
Record Classes in JavaHaim Michael
 
Microservices Design Patterns
Microservices Design PatternsMicroservices Design Patterns
Microservices Design PatternsHaim Michael
 
Structural Pattern Matching in Python
Structural Pattern Matching in PythonStructural Pattern Matching in Python
Structural Pattern Matching in PythonHaim Michael
 
Unit Testing in Python
Unit Testing in PythonUnit Testing in Python
Unit Testing in PythonHaim Michael
 
OOP Best Practices in JavaScript
OOP Best Practices in JavaScriptOOP Best Practices in JavaScript
OOP Best Practices in JavaScriptHaim Michael
 
JavaScript Jump Start 20220214
JavaScript Jump Start 20220214JavaScript Jump Start 20220214
JavaScript Jump Start 20220214Haim Michael
 
Bootstrap Jump Start
Bootstrap Jump StartBootstrap Jump Start
Bootstrap Jump StartHaim Michael
 
Programming in Python on Steroid
Programming in Python on SteroidProgramming in Python on Steroid
Programming in Python on SteroidHaim Michael
 
The matplotlib Library
The matplotlib LibraryThe matplotlib Library
The matplotlib LibraryHaim Michael
 
Pandas meetup 20200908
Pandas meetup 20200908Pandas meetup 20200908
Pandas meetup 20200908Haim Michael
 
Jupyter notebook 20200728
Jupyter notebook 20200728Jupyter notebook 20200728
Jupyter notebook 20200728Haim Michael
 
Node.js Crash Course (Jump Start)
Node.js Crash Course (Jump Start) Node.js Crash Course (Jump Start)
Node.js Crash Course (Jump Start) Haim Michael
 
The Power of Decorators in Python [Meetup]
The Power of Decorators in Python [Meetup]The Power of Decorators in Python [Meetup]
The Power of Decorators in Python [Meetup]Haim Michael
 
Asynchronous JavaScript Programming
Asynchronous JavaScript ProgrammingAsynchronous JavaScript Programming
Asynchronous JavaScript ProgrammingHaim Michael
 

More from Haim Michael (20)

Anti Patterns
Anti PatternsAnti Patterns
Anti Patterns
 
Virtual Threads in Java
Virtual Threads in JavaVirtual Threads in Java
Virtual Threads in Java
 
MongoDB Design Patterns
MongoDB Design PatternsMongoDB Design Patterns
MongoDB Design Patterns
 
Introduction to SQL Injections
Introduction to SQL InjectionsIntroduction to SQL Injections
Introduction to SQL Injections
 
Record Classes in Java
Record Classes in JavaRecord Classes in Java
Record Classes in Java
 
Microservices Design Patterns
Microservices Design PatternsMicroservices Design Patterns
Microservices Design Patterns
 
Structural Pattern Matching in Python
Structural Pattern Matching in PythonStructural Pattern Matching in Python
Structural Pattern Matching in Python
 
Unit Testing in Python
Unit Testing in PythonUnit Testing in Python
Unit Testing in Python
 
OOP Best Practices in JavaScript
OOP Best Practices in JavaScriptOOP Best Practices in JavaScript
OOP Best Practices in JavaScript
 
Java Jump Start
Java Jump StartJava Jump Start
Java Jump Start
 
JavaScript Jump Start 20220214
JavaScript Jump Start 20220214JavaScript Jump Start 20220214
JavaScript Jump Start 20220214
 
Bootstrap Jump Start
Bootstrap Jump StartBootstrap Jump Start
Bootstrap Jump Start
 
Programming in Python on Steroid
Programming in Python on SteroidProgramming in Python on Steroid
Programming in Python on Steroid
 
The matplotlib Library
The matplotlib LibraryThe matplotlib Library
The matplotlib Library
 
Pandas meetup 20200908
Pandas meetup 20200908Pandas meetup 20200908
Pandas meetup 20200908
 
Jupyter notebook 20200728
Jupyter notebook 20200728Jupyter notebook 20200728
Jupyter notebook 20200728
 
Node.js Crash Course (Jump Start)
Node.js Crash Course (Jump Start) Node.js Crash Course (Jump Start)
Node.js Crash Course (Jump Start)
 
The Power of Decorators in Python [Meetup]
The Power of Decorators in Python [Meetup]The Power of Decorators in Python [Meetup]
The Power of Decorators in Python [Meetup]
 
Asynchronous JavaScript Programming
Asynchronous JavaScript ProgrammingAsynchronous JavaScript Programming
Asynchronous JavaScript Programming
 
Python Jump Start
Python Jump StartPython Jump Start
Python Jump Start
 

Recently uploaded

MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Software Coding for software engineering
Software Coding for software engineeringSoftware Coding for software engineering
Software Coding for software engineeringssuserb3a23b
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...confluent
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalLionel Briand
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsChristian Birchler
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Developmentvyaparkranti
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfDrew Moseley
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsSafe Software
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfExploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfkalichargn70th171
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Mater
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 

Recently uploaded (20)

Odoo Development Company in India | Devintelle Consulting Service
Odoo Development Company in India | Devintelle Consulting ServiceOdoo Development Company in India | Devintelle Consulting Service
Odoo Development Company in India | Devintelle Consulting Service
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Software Coding for software engineering
Software Coding for software engineeringSoftware Coding for software engineering
Software Coding for software engineering
 
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
Catch the Wave: SAP Event-Driven and Data Streaming for the Intelligence Ente...
 
Advantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your BusinessAdvantages of Odoo ERP 17 for Your Business
Advantages of Odoo ERP 17 for Your Business
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive Goal
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Development
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdf
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data Streams
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdfExploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
Exploring Selenium_Appium Frameworks for Seamless Integration with HeadSpin.pdf
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 

What is new in Python 3.9

  • 1. What is new in Python 3.9 Haim Michael March 8th , 2021 All logos, trade marks and brand names used in this presentation belong to the respective owners. life michae l Let's be on The Edge www.lifemichael.com
  • 2. © 2008 Haim Michael 20150805 Python 3.9
  • 3. © 2008 Haim Michael 20150805 The dict Union | Operator  The dict union operator | return a new dict consisting of the left operand merged with the right operand, each of which must be a dict (or an instance of a dict subclass).  When the key appears in both operands, the last-seen value (i.e. that from the right-hand operand) wins. https://www.python.org/dev/peps/pep-0584/
  • 4. © 2008 Haim Michael 20150805 The dict Union | Operator dict1 = {1:'one', 2:'two', 3:'three'} dict2 = {3:'three',4:'four',5:'five',6:'six'} dict3 = dict1 | dict2 print(dict3)
  • 5. © 2008 Haim Michael 20150805 Type Hinting Generics in Collections  We can now use the generics syntax when using the standard collections in Python. We are no longer limited to using generics with the collections the typing module includes.  As of Python 3.9 we no longer need the standard collections the typing module includes. https://www.python.org/dev/peps/pep-0585/
  • 6. © 2008 Haim Michael 20150805 Type Hinting Generics in Collections numbers: list[int] = [23, 3, 6] student: tuple[str, str, float, int] = ("mosh", "solomon", 98.2, 2343243) nicknames: dict[str, str] = {"mosh": "moshe", "tal": "talia", "avi": "avraham"} winners: set[str] = {"dave", "mark", "tal", "doron", "jane"} print(numbers) print(student) print(nicknames) print(winners)
  • 7. © 2008 Haim Michael 20150805 The Prefix and Suffix Methods  The methods, removeprefix() and removesuffix(), are now available when using Python's various string objects.  These methods would remove a prefix or suffix (respectively) from a string, if present.  These two methods will be available when using objects of the types str, bytes, bytearray and collections.UserString. https://www.python.org/dev/peps/pep-0616/
  • 8. © 2008 Haim Michael 20150805 The Prefix and Suffix Methods filenames:list[str] = [ "king.txt.txt", "temp.txt", "pep8song.txt", "data.txt"] for filename in filenames: if filename.endswith(".txt.txt"): print(filename.removesuffix(".txt")) else: print(filename)
  • 9. © 2008 Haim Michael 20150805 The Prefix and Suffix Methods names: list[str] = ["Dr.Mosh Levin", "Dr.Ronan Cohen", "Ran Roze"] for name in names: if name.startswith("Dr."): print(name.removeprefix("Dr.")) else: print(name)
  • 10. © 2008 Haim Michael 20150805 Annotated Type Hints  The possibility to annotate a function allows us to add arbitrary metadata to functions we define. def calc(distance: "meter", time: "second") -> "km per hour": return 3600 * (distance / 1000) / time  As of Python 3.9 we can use the typing.Annotated from typing import Annotated def calc( distance: Annotated[int, "meter"], time: Annotated[float, "second"] ) -> Annotated[float, "km per hour"]: return 3600 * (distance / 1000) / time
  • 11. © 2008 Haim Michael 20150805 Annotated Type Hints  We can (as usual) access the annotations through the .__annotations__ attribute. from typing import Annotated def calc( distance: Annotated[int, "meter"], time: Annotated[float, "second"] ) -> Annotated[float, "km per hour"]: return 3600 * (distance / 1000) / time print(calc.__annotations__)
  • 12. © 2008 Haim Michael 20150805 Annotated Type Hints  We can keep our code more readable by using type aliases. from typing import Annotated Meter = Annotated[int, "meter"] Second = Annotated[int, "second"] KmPerHour = Annotated[float, "km per hour"] def calc(distance: Meter, time: Second) -> KmPerHour: return 3600 * (distance / 1000) / time print(calc.__annotations__)
  • 13. © 2008 Haim Michael 20150805 Powerful Parser  One of the main components of the Python interpreter is the parser.  As of Python 3.9, we have a new parser. The new parser was developed based on Guido's research of PEG (Parsing Expression Grammar) parsers.
  • 14. © 2008 Haim Michael 20150805 Powerful Parser  The interpreter (in Python 3.9) includes both the new PEG parser and the old LL(1) parser. The PEG parser is the default one. It is still possible to use the LL(1) old one by using the -X oldparser command-line flag: $ python -X oldparser program.py
  • 15. © 2008 Haim Michael 20150805 Powerful Parser  The old parser will be removed in Python 3.10. This will allow the implementation of new features without the limitations of an LL(1) grammar (e.g. implementing structural pattern matching).  The performance of both parsers, the PEG parser and the LL(1) parser, is similar.
  • 16. © 2008 Haim Michael 20150805 The graphlib Module  As of Python 3.9, the standard library includes the graphlib new module. from graphlib import TopologicalSorter dependencies = { "Java EE": {"Java", "Angular"}, "Angular": {"JavaScript"}, "Java": {"C++", "SQL"}, "C++": {"C"} } sorter = TopologicalSorter(dependencies) print(list(sorter.static_order()))
  • 17. © 2008 Haim Michael 20150805 The Least Common Multiple(LCM)  As of Python 3.9, we can easily find the least common multiple (LCM) by calling the math.lcm function. import math num1 = 5 num2 = 7 num3 = 3 result = math.lcm(num1,num2,num3) print(result)
  • 18. © 2008 Haim Michael 20150805 HTTP Status Codes  As of Python 3.9, the http module includes two more status codes: 103 (Early Hints) and 425 (Too Early). from http import HTTPStatus print(HTTPStatus.OK) print(HTTPStatus.OK.description) print(HTTPStatus.OK.value) print(HTTPStatus.OK.phrase) print(HTTPStatus.NOT_FOUND) print(HTTPStatus.NOT_FOUND.description) print(HTTPStatus.NOT_FOUND.value) print(HTTPStatus.NOT_FOUND.phrase) print(HTTPStatus.EARLY_HINTS) print(HTTPStatus.TOO_EARLY)
  • 19. © 2008 Haim Michael 20150805 The zoneinfo Module  The zoneinfo was added in Python 3.9. It complements the datetime module by allowing us getting information about the time zone. from datetime import datetime from zoneinfo import ZoneInfo vancouver = ZoneInfo("America/Vancouver") release = datetime(2020, 11, 25, 2, 12, tzinfo=vancouver) print(release)
  • 20. © 2008 Haim Michael 20150805 The zoneinfo Module  The following code sample prints out the available time zones. import zoneinfo zones = zoneinfo.available_timezones() print(len(zones)) print(zones)
  • 21. © 2009 Haim Michael All Rights Reserved 21 Questions & Answers Thanks for Your Time! Haim Michael haim.michael@lifemichael.com +972+3+3726013 ext:700 +972+54+6655837 (whatsapp) life michael