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: |

What is Secret Chats of Telegram

Secret Chats are one of the service’s additional security features; it allows messages to be sent with client-to-client encryption. This setup means that, unlike regular messages, these secret messages can only be accessed from the device’s that initiated and accepted the chat. Additionally, Telegram notes that secret chats leave no trace on the company’s services and offer a self-destruct timer.

PyThrone from us


Telegram PyThrone
FROM USA