PYTHONL Telegram 5103
This media is not supported in your browser
VIEW IN TELEGRAM
πŸ”₯ Π‘ΠΎΠ²Π΅Ρ‚ ΠΏΠΎ Python: Π½Π΅ΠΎΠΆΠΈΠ΄Π°Π½Π½ΠΎΠ΅ ΠΏΠΎΠ²Π΅Π΄Π΅Π½ΠΈΠ΅ с измСняСмыми Π°Ρ€Π³ΡƒΠΌΠ΅Π½Ρ‚Π°ΠΌΠΈ ΠΏΠΎ ΡƒΠΌΠΎΠ»Ρ‡Π°Π½ΠΈΡŽ

Если Π² Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠΈ Π·Π°Π΄Π°Ρ‚ΡŒ Π°Ρ€Π³ΡƒΠΌΠ΅Π½Ρ‚ ΠΏΠΎ ΡƒΠΌΠΎΠ»Ρ‡Π°Π½ΠΈΡŽ ΠΊΠ°ΠΊ list ΠΈΠ»ΠΈ dict, Ρ‚ΠΎ этот ΠΎΠ±ΡŠΠ΅ΠΊΡ‚ создаётся ΠΎΠ΄ΠΈΠ½ Ρ€Π°Π· β€” ΠΏΡ€ΠΈ ΠΎΠΏΡ€Π΅Π΄Π΅Π»Π΅Π½ΠΈΠΈ Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠΈ.

Из-Π·Π° этого всС Π²Ρ‹Π·ΠΎΠ²Ρ‹ Π±ΡƒΠ΄ΡƒΡ‚ Π΄Π΅Π»ΠΈΡ‚ΡŒ ΠΎΠ΄ΠΈΠ½ ΠΈ Ρ‚ΠΎΡ‚ ΠΆΠ΅ ΠΎΠ±ΡŠΠ΅ΠΊΡ‚, Ρ‡Ρ‚ΠΎ часто ΠΏΡ€ΠΈΠ²ΠΎΠ΄ΠΈΡ‚ ΠΊ Π±Π°Π³Π°ΠΌ.

ΠŸΡ€Π°Π²ΠΈΠ»ΡŒΠ½Ρ‹ΠΉ способ β€” ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒ `None` ΠΈ ΡΠΎΠ·Π΄Π°Π²Π°Ρ‚ΡŒ Π½ΠΎΠ²Ρ‹ΠΉ ΠΎΠ±ΡŠΠ΅ΠΊΡ‚ Π²Π½ΡƒΡ‚Ρ€ΠΈ Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠΈ.


def bad_append(x, data=[]):
data.append(x)
return data

print(bad_append(1)) # [1]
print(bad_append(2)) # [1, 2] <-- Π½Π΅ΠΎΠΆΠΈΠ΄Π°Π½Π½ΠΎ!


def good_append(x, data=None):
if data is None:
data = []
data.append(x)
return data

print(good_append(1)) # [1]
print(good_append(2)) # [2]


Π˜ΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉΡ‚Π΅ этот ΠΏΡ€ΠΈΡ‘ΠΌ, Ρ‡Ρ‚ΠΎΠ±Ρ‹ Π½Π΅ ΠΏΠΎΠΏΠ°ΡΡ‚ΡŒΡΡ Π½Π° скрытыС Π±Π°Π³ΠΈ с Π°Ρ€Π³ΡƒΠΌΠ΅Π½Ρ‚Π°ΠΌΠΈ ΠΏΠΎ ΡƒΠΌΠΎΠ»Ρ‡Π°Π½ΠΈΡŽ.
❀22πŸ‘13πŸ”₯5😱2



tgoop.com/pythonl/5103
Create:
Last Update:

πŸ”₯ Π‘ΠΎΠ²Π΅Ρ‚ ΠΏΠΎ Python: Π½Π΅ΠΎΠΆΠΈΠ΄Π°Π½Π½ΠΎΠ΅ ΠΏΠΎΠ²Π΅Π΄Π΅Π½ΠΈΠ΅ с измСняСмыми Π°Ρ€Π³ΡƒΠΌΠ΅Π½Ρ‚Π°ΠΌΠΈ ΠΏΠΎ ΡƒΠΌΠΎΠ»Ρ‡Π°Π½ΠΈΡŽ

Если Π² Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠΈ Π·Π°Π΄Π°Ρ‚ΡŒ Π°Ρ€Π³ΡƒΠΌΠ΅Π½Ρ‚ ΠΏΠΎ ΡƒΠΌΠΎΠ»Ρ‡Π°Π½ΠΈΡŽ ΠΊΠ°ΠΊ list ΠΈΠ»ΠΈ dict, Ρ‚ΠΎ этот ΠΎΠ±ΡŠΠ΅ΠΊΡ‚ создаётся ΠΎΠ΄ΠΈΠ½ Ρ€Π°Π· β€” ΠΏΡ€ΠΈ ΠΎΠΏΡ€Π΅Π΄Π΅Π»Π΅Π½ΠΈΠΈ Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠΈ.

Из-Π·Π° этого всС Π²Ρ‹Π·ΠΎΠ²Ρ‹ Π±ΡƒΠ΄ΡƒΡ‚ Π΄Π΅Π»ΠΈΡ‚ΡŒ ΠΎΠ΄ΠΈΠ½ ΠΈ Ρ‚ΠΎΡ‚ ΠΆΠ΅ ΠΎΠ±ΡŠΠ΅ΠΊΡ‚, Ρ‡Ρ‚ΠΎ часто ΠΏΡ€ΠΈΠ²ΠΎΠ΄ΠΈΡ‚ ΠΊ Π±Π°Π³Π°ΠΌ.

ΠŸΡ€Π°Π²ΠΈΠ»ΡŒΠ½Ρ‹ΠΉ способ β€” ΠΈΡΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚ΡŒ `None` ΠΈ ΡΠΎΠ·Π΄Π°Π²Π°Ρ‚ΡŒ Π½ΠΎΠ²Ρ‹ΠΉ ΠΎΠ±ΡŠΠ΅ΠΊΡ‚ Π²Π½ΡƒΡ‚Ρ€ΠΈ Ρ„ΡƒΠ½ΠΊΡ†ΠΈΠΈ.


def bad_append(x, data=[]):
data.append(x)
return data

print(bad_append(1)) # [1]
print(bad_append(2)) # [1, 2] <-- Π½Π΅ΠΎΠΆΠΈΠ΄Π°Π½Π½ΠΎ!


def good_append(x, data=None):
if data is None:
data = []
data.append(x)
return data

print(good_append(1)) # [1]
print(good_append(2)) # [2]


Π˜ΡΠΏΠΎΠ»ΡŒΠ·ΡƒΠΉΡ‚Π΅ этот ΠΏΡ€ΠΈΡ‘ΠΌ, Ρ‡Ρ‚ΠΎΠ±Ρ‹ Π½Π΅ ΠΏΠΎΠΏΠ°ΡΡ‚ΡŒΡΡ Π½Π° скрытыС Π±Π°Π³ΠΈ с Π°Ρ€Π³ΡƒΠΌΠ΅Π½Ρ‚Π°ΠΌΠΈ ΠΏΠΎ ΡƒΠΌΠΎΠ»Ρ‡Π°Π½ΠΈΡŽ.

BY Python/ django


Share with your friend now:
tgoop.com/pythonl/5103

View MORE
Open in Telegram


Telegram News

Date: |

Commenting about the court's concerns about the spread of false information related to the elections, Minister Fachin noted Brazil is "facing circumstances that could put Brazil's democracy at risk." During the meeting, the information technology secretary at the TSE, Julio Valente, put forward a list of requests the court believes will disinformation. In 2018, Telegram’s audience reached 200 million people, with 500,000 new users joining the messenger every day. It was launched for iOS on 14 August 2013 and Android on 20 October 2013. fire bomb molotov November 18 Dylan Hollingsworth yau ma tei With the sharp downturn in the crypto market, yelling has become a coping mechanism for many crypto traders. This screaming therapy became popular after the surge of Goblintown Ethereum NFTs at the end of May or early June. Here, holders made incoherent groaning sounds in late-night Twitter spaces. They also role-played as urine-loving Goblin creatures. Among the requests, the Brazilian electoral Court wanted to know if they could obtain data on the origins of malicious content posted on the platform. According to the TSE, this would enable the authorities to track false content and identify the user responsible for publishing it in the first place.
from us


Telegram Python/ django
FROM American