SlideShare a Scribd company logo
Python 3
   Андрей Светлов

      @andrew_svetlov
andrew.svetlov@gmail.com
http://asvetlov.blogspot.com
Releases
2.6 — Oct 2008
3.0 — Dec 2008
3.1 — Jul 2009
2.7 — Jul 2010
3.2 — Feb 2011
3.3 — Aug 2012
Строки


         Только unicode

 Utf-8 — кодировка по умолчанию

Неявные преобразования str↔bytes
          запрещены.
Числа


      Unified int

 Long — отсутствует

Дерево числовых типов

Decimal — теперь на C
Форматирование строк



"{a:s} {b:.2f}".format(a='строка', b=3.14159)

"{c[0]}-{c[1]}".format(c=(1, 2))

"{0.x}, {0.y}".format(coord)
Function annotations


def f(a: int, b: float) -> str:
  return "{}:{}".format(a, b)

>>> f.__annotations__
{'a': builtins.int, 'b': builtins.float,
    'return': builtins.str}
Nonlocal

def f():
   a=0
   def g():
      nonlocal a
      a += 1
   g()
   return a
Keyword only
>>> def f(a, b=0, *, c, d='Smith'):
...   pass
>>> f(1, c='John', d='Doe')
>>> f(1, c='Mary')
>>> f(1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: f() needs keyword-only argument c
Extended iterable unpacking
a, *rest = range(5)
a, *rest, b = range(5)
Comprehensions
{key(k): value(k) for k in range(5)}


{f(k) for k in range(5)}


{1, 2, 3, 4, 5}
ABC and new `super()`
class Base(metaclass=abc.ABCMeta):
  @abc.abstractmethod
  def f(self, a):
    """Comprehensive doc"""
    pass


class A(Base):
  def f(self, a):
Exception chain
def f():
      try:
         1/0
      except Exception as ex:
         raise RuntimeError("Oops") from ex
f()
Exception chain 2
Traceback (most recent call last):
 File "<string>", line 3, in f
   1/0
ZeroDivisionError: division by zero


 The above exception was the direct cause of
the following exception:


Traceback (most recent call last):
Абстрактные типы для коллекций
Hashable
Iterable
Sized
Container
Callable
Sequence
etc.
OrderedDict
>>> d = {'banana': 3, 'apple':4, 'pear': 1, 'orange':
 2}


# dictionary sorted by key
>>> OrderedDict(sorted(d.items(), key=lambda t:
 t[0]))
OrderedDict([('apple', 4), ('banana', 3), ('orange',
 2), ('pear', 1)])
Counter
>>> cnt = Counter()
>>> for word in ['red', 'blue', 'red',
…          'green', 'blue', 'blue']:
...   cnt[word] += 1
>>> cnt
Counter({'blue': 3, 'red': 2, 'green': 1})
Yield from
>>> def g(x):
...   yield from range(x, 0, -1)
...   yield from range(x)
...
>>> list(g(5))
[5, 4, 3, 2, 1, 0, 1, 2, 3, 4]
Новые метаклассы
class OrderedClass(type):
  @classmethod
   def __prepare__(metacls, name, bases,
 **kwds):
    return collections.OrderedDict()
  def __new__(cls, name, bases, classdict):
     result = type.__new__(cls, name, bases,
 dict(classdict))
    result.members = tuple(classdict)
Незаметные вкусности
Новый GIL
Importlib
Stable ABI
PYC repository dirs
ABI version tagged .so files
Packaging
Вопросы?
      @andrew_svetlov
andrew.svetlov@gmail.com
http://asvetlov.blogspot.com

More Related Content

PDF
Python3 cheatsheet
Gil Cohen
 
PPTX
Python Tidbits
Mitchell Vitez
 
PDF
Cheat sheet python3
sxw2k
 
PPT
Python легко и просто. Красиво решаем повседневные задачи
Maxim Kulsha
 
PDF
밑바닥부터 시작하는 의료 AI
NAVER Engineering
 
PDF
Clustering com numpy e cython
Anderson Dantas
 
PDF
Let's golang
SuHyun Jeon
 
PPTX
TCO in Python via bytecode manipulation.
lnikolaeva
 
Python3 cheatsheet
Gil Cohen
 
Python Tidbits
Mitchell Vitez
 
Cheat sheet python3
sxw2k
 
Python легко и просто. Красиво решаем повседневные задачи
Maxim Kulsha
 
밑바닥부터 시작하는 의료 AI
NAVER Engineering
 
Clustering com numpy e cython
Anderson Dantas
 
Let's golang
SuHyun Jeon
 
TCO in Python via bytecode manipulation.
lnikolaeva
 

What's hot (20)

PPTX
The groovy puzzlers (as Presented at JavaOne 2014)
GroovyPuzzlers
 
PDF
Python_ 3 CheatSheet
Dr. Volkan OBAN
 
PDF
Allison Kaptur: Bytes in the Machine: Inside the CPython interpreter, PyGotha...
akaptur
 
PDF
Beginners python cheat sheet - Basic knowledge
O T
 
PDF
Swift - Krzysztof Skarupa
Sunscrapers
 
PDF
Byterun, a Python bytecode interpreter - Allison Kaptur at NYCPython
akaptur
 
ODP
The secrets of inverse brogramming
Richie Cotton
 
PDF
Palestra sobre Collections com Python
pugpe
 
PDF
Python Programming: Data Structure
Chan Shik Lim
 
PDF
Exploring slides
akaptur
 
PDF
Codigos
Brian Joseff
 
PDF
Talk Code
Agiliq Solutions
 
PDF
Diving into byte code optimization in python
Chetan Giridhar
 
PDF
Postgresql 9.3 overview
Aveic
 
PPTX
Python basic
sewoo lee
 
PDF
Elixir & Phoenix – fast, concurrent and explicit
Tobias Pfeiffer
 
PDF
Elixir & Phoenix – fast, concurrent and explicit
Tobias Pfeiffer
 
PPTX
Super Advanced Python –act1
Ke Wei Louis
 
PDF
1 pythonbasic
pramod naik
 
PDF
The Ring programming language version 1.5.2 book - Part 45 of 181
Mahmoud Samir Fayed
 
The groovy puzzlers (as Presented at JavaOne 2014)
GroovyPuzzlers
 
Python_ 3 CheatSheet
Dr. Volkan OBAN
 
Allison Kaptur: Bytes in the Machine: Inside the CPython interpreter, PyGotha...
akaptur
 
Beginners python cheat sheet - Basic knowledge
O T
 
Swift - Krzysztof Skarupa
Sunscrapers
 
Byterun, a Python bytecode interpreter - Allison Kaptur at NYCPython
akaptur
 
The secrets of inverse brogramming
Richie Cotton
 
Palestra sobre Collections com Python
pugpe
 
Python Programming: Data Structure
Chan Shik Lim
 
Exploring slides
akaptur
 
Codigos
Brian Joseff
 
Talk Code
Agiliq Solutions
 
Diving into byte code optimization in python
Chetan Giridhar
 
Postgresql 9.3 overview
Aveic
 
Python basic
sewoo lee
 
Elixir & Phoenix – fast, concurrent and explicit
Tobias Pfeiffer
 
Elixir & Phoenix – fast, concurrent and explicit
Tobias Pfeiffer
 
Super Advanced Python –act1
Ke Wei Louis
 
1 pythonbasic
pramod naik
 
The Ring programming language version 1.5.2 book - Part 45 of 181
Mahmoud Samir Fayed
 
Ad

Similar to Py3k (20)

ODP
Intro
Cosmin Poieana
 
PPTX
Python 표준 라이브러리
용 최
 
PDF
An overview of Python 2.7
decoupled
 
PDF
A tour of Python
Aleksandar Veselinovic
 
PDF
Functions in python
Ilian Iliev
 
PPTX
Python 내장 함수
용 최
 
PDF
R for you
Andreas Chandra
 
PPTX
GE8151 Problem Solving and Python Programming
Muthu Vinayagam
 
PPTX
R programming language
Alberto Minetti
 
PPTX
Oh Composable World!
Brian Lonsdorf
 
PDF
Basic R Data Manipulation
Chu An
 
ODP
Python course Day 1
Karin Lagesen
 
PDF
Faster Python, FOSDEM
Victor Stinner
 
PDF
Python.pdf
TanTran598844
 
PPTX
Python Cheat Sheet Presentation Learning
Naseer-ul-Hassan Rehman
 
PPTX
R
exsuns
 
PDF
8799.pdfOr else the work is fine only. Lot to learn buddy.... Improve your ba...
Yashpatel821746
 
PDF
Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...
Yashpatel821746
 
PDF
PYTHONOr else the work is fine only. Lot to learn buddy.... Improve your basi...
Yashpatel821746
 
DOCX
Advanced Programming With R Software-WithSolutions
hodpgcs1
 
Python 표준 라이브러리
용 최
 
An overview of Python 2.7
decoupled
 
A tour of Python
Aleksandar Veselinovic
 
Functions in python
Ilian Iliev
 
Python 내장 함수
용 최
 
R for you
Andreas Chandra
 
GE8151 Problem Solving and Python Programming
Muthu Vinayagam
 
R programming language
Alberto Minetti
 
Oh Composable World!
Brian Lonsdorf
 
Basic R Data Manipulation
Chu An
 
Python course Day 1
Karin Lagesen
 
Faster Python, FOSDEM
Victor Stinner
 
Python.pdf
TanTran598844
 
Python Cheat Sheet Presentation Learning
Naseer-ul-Hassan Rehman
 
8799.pdfOr else the work is fine only. Lot to learn buddy.... Improve your ba...
Yashpatel821746
 
Or else the work is fine only. Lot to learn buddy.... Improve your basics in ...
Yashpatel821746
 
PYTHONOr else the work is fine only. Lot to learn buddy.... Improve your basi...
Yashpatel821746
 
Advanced Programming With R Software-WithSolutions
hodpgcs1
 
Ad

More from Andrew Svetlov (6)

PDF
Writing Open Source Library
Andrew Svetlov
 
PDF
Asyncio
Andrew Svetlov
 
ODP
Import
Andrew Svetlov
 
PDF
Интерфейсы в Python
Andrew Svetlov
 
Writing Open Source Library
Andrew Svetlov
 
Интерфейсы в Python
Andrew Svetlov
 

Recently uploaded (20)

PDF
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
PPTX
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
PPTX
The Future of AI & Machine Learning.pptx
pritsen4700
 
PDF
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
PPTX
Agile Chennai 18-19 July 2025 | Emerging patterns in Agentic AI by Bharani Su...
AgileNetwork
 
PDF
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
 
PDF
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
PDF
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
PDF
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
PDF
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 
PDF
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
PPTX
Agile Chennai 18-19 July 2025 Ideathon | AI Powered Microfinance Literacy Gui...
AgileNetwork
 
PDF
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
PPTX
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
PDF
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
PPTX
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
PDF
Software Development Methodologies in 2025
KodekX
 
PDF
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
The Future of AI & Machine Learning.pptx
pritsen4700
 
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
Agile Chennai 18-19 July 2025 | Emerging patterns in Agentic AI by Bharani Su...
AgileNetwork
 
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
 
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
Agile Chennai 18-19 July 2025 Ideathon | AI Powered Microfinance Literacy Gui...
AgileNetwork
 
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
Software Development Methodologies in 2025
KodekX
 
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 

Py3k