We're sunsetting PodQuest on 2025-07-28. Thank you for your support!
Export Podcast Subscriptions
cover of episode #424 We Will Test in Production

#424 We Will Test in Production

2025/3/17
logo of podcast Python Bytes

Python Bytes

AI Deep Dive AI Chapters Transcript
People
B
Brian
Python 开发者和播客主持人,专注于测试和软件开发教育。
M
Michael
帮助医生和高收入专业人士管理财务的金融教育者和播客主持人。
Topics
Brian: 我发现Python中的四舍五入规则与我们通常学习的规则不同,它遵循IEEE 754标准,采用向偶数舍入的方式。对于以.5结尾的数字,它总是舍入到最近的偶数。例如,round(0.5)的结果是0,round(1.5)的结果是2。虽然这种方式在统计学上更合理,但与我们日常习惯的四舍五入方法不同。如果需要使用传统的四舍五入方法,可以使用decimal模块。 Michael: 我了解到CPython项目添加了尾调用优化,这显著提升了Python解释器的性能。这项优化主要体现在对bytecode指令的执行方式上,通过重用栈帧来减少内存分配,从而提高效率。根据测试结果,这项优化平均可以提升10%的性能,某些情况下甚至可以提升40%。这相当于两到三个CPython版本的性能提升总和。这项优化已经合并到Python 3.14版本中。

Deep Dive

Chapters
The podcast starts with introductions, sponsor mentions, and details about how to connect with the hosts and receive the newsletter. They also mention the value of the show notes for further learning.
  • Podcast introduction and sponsor announcements.
  • Information on connecting with the hosts and subscribing to the newsletter.

Shownotes Transcript

Topics covered in this episode:

- **[The weird quirk with rounding in Python](https://itnext.io/the-weird-quirk-with-rounding-in-python-e6cd98cb3d55?featured_on=pythonbytes))**

Watch on YouTube)

About the show

Sponsored by us! Support our work through:

Connect with the hosts

Join us on YouTube at pythonbytes.fm/live) to be part of the audience. Usually Monday at 10am PT. Older video versions available there too.

Finally, if you want an artisanal, hand-crafted digest of every week of the show notes in email form? Add your name and email to our friends of the show list), we'll never share it.

Brian #1: The weird quirk with rounding in Python)

  • Tom Nijhof-Verheesb

  • With numbers ending in .5, Python always rounds to an even number.

  • round(0.5) → 0

  • round(1.5) → 2

  • etc

  • This follows IEEE 754

  • You can use decimal if you need a different behavior.

Michael #2: Python interpreter adds tail calls)

  • Ken Jin, a member of the project, has merged a new set of changes) that have been benchmarked) as improving performance by 10% for some architectures.

  • "Speedup is roughly equal to 2 minor CPython releases worth of improvements. For example, CPython 3.12 roughly sped up by 5%.”

Brian #3: Remove punctuation from a string with translate and maketrans)

  • Rodrigo

  • “Don't use the method replace to remove punctuation from a Python string. Instead, use the method translate.”

Michael #4: Extra, extra, extra

Extras

Joke: Startrek Testing)