Quick question about CPython interpreter

Michael Torrie torriem at gmail.com
Mon Oct 17 11:38:56 EDT 2022


On 10/14/22 16:25, DFS wrote:
> ---------------------------------------------------------------------
> this does a str() conversion in the loop
> ---------------------------------------------------------------------
> for i in range(cells.count()):
>    if text == str(ID):
>      break
> 
> 
> ---------------------------------------------------------
> this does one str() conversion before the loop
> ---------------------------------------------------------
> strID = str(ID)
> for i in range(cells.count()):
>    if text == strID:
>      break
> 
> 
> But does CPython interpret the str() conversion away and essentially do 
> it for me in the first example?

No.

You can use the dis module to show you what CPython is doing under the hood.


More information about the Python-list mailing list