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


telegram Telegram | DID YOU KNOW?

Date: |

Traders also expressed uncertainty about the situation with China Evergrande, as the indebted property company has not provided clarification about a key interest payment.In economic news, the Commerce Department reported an unexpected increase in U.S. new home sales in August.Crude oil prices climbed Friday and front-month WTI oil futures contracts saw gains for a fifth straight week amid tighter supplies. West Texas Intermediate Crude oil futures for November rose $0.68 or 0.9 percent at 73.98 a barrel. WTI Crude futures gained 2.8 percent for the week.

telegram from in


Telegram PyThrone
FROM USA