What does = (equal) do in f-strings inside the expression curly brackets?

This is actually a brand-new feature as of Python 3.8. Added an = specifier to f-strings. An f-string such as f'{expr=}’ will expand to the text of the expression, an equal sign, then the representation of the evaluated expression. Essentially, it facilitates the frequent use-case of print-debugging, so, whereas we would normally have to write: … Read more

What are assignment expressions (using the “walrus” or “:=” operator)? Why was this syntax added?

PEP 572 contains many of the details, especially for the first question. I’ll try to summarise/quote concisely arguably some of the most important parts of the PEP: Rationale Allowing this form of assignment within comprehensions, such as list comprehensions, and lambda functions where traditional assignments are forbidden. This can also facilitate interactive debugging without the … Read more

Install Python 3.8 kernel in Google Colaboratory

I have found how to run Python 3.8 notebook on Colab. install Anaconda3 add (fake) google.colab library start jupyterlab access it with ngrok Here’s the code # install Anaconda3 !wget -qO ac.sh https://repo.anaconda.com/archive/Anaconda3-2020.07-Linux-x86_64.sh !bash ./ac.sh -b # a fake google.colab library !ln -s /usr/local/lib/python3.7/dist-packages/google \ /root/anaconda3/lib/python3.8/site-packages/google # start jupyterlab, which now has Python3 = 3.8 … Read more

PyWin32 and Python 3.8.0

Spoiler alert!!! Applied #2.2. (from below) to the original .whls, and published them on [GitHub]: CristiFati/Prebuilt-Binaries – (master) Prebuilt-Binaries/PyWin32/v225 (win_amd64, win32 for Python 3.8). After installing (one of) them, existing code should work OOTB (with respect to this issue). Install steps: Download the .whl that matches your Python architecture (64bit, 32bit – for more details … Read more

“:=” syntax and assignment expressions: what and why?

PEP 572 contains many of the details, especially for the first question. I’ll try to summarise/quote concisely arguably some of the most important parts of the PEP: Rationale Allowing this form of assignment within comprehensions, such as list comprehensions, and lambda functions where traditional assignments are forbidden. This can also facilitate interactive debugging without the … Read more

How to make ball bounce off wall with PyGame?

The issue are the multiple nested loops. You have an application loop, so use it. Continuously move the ball in the loop: box.y -= box.vel_y box.x += box.vel_x Define a rectangular region for the ball by a pygame.Rect object: bounds = window.get_rect() # full screen or bounds = pygame.Rect(450, 200, 300, 200) # rectangular region … Read more