Telegram Group & Telegram Channel
Что выведет этот код?

Строки длиной до 4096 (до версии 3.7 длиной до 21) кэшируются.
s1 = "a" * 4096
s2 = "a" * 4096

print(s1 is s2) # True

s1 = "a" * 4097
s2 = "a" * 4097

print(s1 is s2) # False


Строки не кэшируются, если они созданы в рантайме:
s1 = "python"
s2 = "".join(["p", "y", "t", "h", "o", "n"]) # выражение выполняется в рантайме

print(s1 is s2) # False


Так же следует понимать, что это может поменяться в любой момент и лучше сравнивать строки через ==, а не через is.

#string #строки



tg-me.com/pythrone/9
Create:
Last Update:

Что выведет этот код?

Строки длиной до 4096 (до версии 3.7 длиной до 21) кэшируются.
s1 = "a" * 4096
s2 = "a" * 4096

print(s1 is s2) # True

s1 = "a" * 4097
s2 = "a" * 4097

print(s1 is s2) # False


Строки не кэшируются, если они созданы в рантайме:
s1 = "python"
s2 = "".join(["p", "y", "t", "h", "o", "n"]) # выражение выполняется в рантайме

print(s1 is s2) # False


Так же следует понимать, что это может поменяться в любой момент и лучше сравнивать строки через ==, а не через is.

#string #строки

BY PyThrone




Share with your friend now:
tg-me.com/pythrone/9

View MORE
Open in Telegram


PyThrone Telegram | DID YOU KNOW?

Date: |

A project of our size needs at least a few hundred million dollars per year to keep going,” Mr. Durov wrote in his public channel on Telegram late last year. “While doing that, we will remain independent and stay true to our values, redefining how a tech company should operate.

How Does Telegram Make Money?

Telegram is a free app and runs on donations. According to a blog on the telegram: We believe in fast and secure messaging that is also 100% free. Pavel Durov, who shares our vision, supplied Telegram with a generous donation, so we have quite enough money for the time being. If Telegram runs out, we will introduce non-essential paid options to support the infrastructure and finance developer salaries. But making profits will never be an end-goal for Telegram.

PyThrone from in


Telegram PyThrone
FROM USA