PYLAB Telegram 423
Python_Labs🐍
فرض کنید میخواهید اگر مقداری وجود داشت،آن را بریزید در متغیری ، اما اگر نبود، یک مقدار پیش فرض در آن بریزید، چگونه مینویسید؟
یکی از دوستان فیدبک داد:

خب همینجوری هم می‌شد از مقدار دیفالت پارامتر‌ها استفاده کرد بحای اینکه None داد بهشون
def foo(bar=10):
return bar

خب تو این مثال حق با ایشونه.
یه نمونه ای که میتونه تو این روش که گفته شد مفید باشه اون موقعیه که به دلایلی ممکنه به تابعمون اصلا None پاس بدند، در اون صورت مقدار دیفالت تابع بازنویسی میشه با None و کارمون خراب میشه.

نمونه ی دیگری سراغ دارید که این پترن به کارتون بیاد؟



tgoop.com/PyLab/423
Create:
Last Update:

یکی از دوستان فیدبک داد:

خب همینجوری هم می‌شد از مقدار دیفالت پارامتر‌ها استفاده کرد بحای اینکه None داد بهشون
def foo(bar=10):
return bar

خب تو این مثال حق با ایشونه.
یه نمونه ای که میتونه تو این روش که گفته شد مفید باشه اون موقعیه که به دلایلی ممکنه به تابعمون اصلا None پاس بدند، در اون صورت مقدار دیفالت تابع بازنویسی میشه با None و کارمون خراب میشه.

نمونه ی دیگری سراغ دارید که این پترن به کارتون بیاد؟

BY Python_Labs🐍




Share with your friend now:
tgoop.com/PyLab/423

View MORE
Open in Telegram


Telegram News

Date: |

End-to-end encryption is an important feature in messaging, as it's the first step in protecting users from surveillance. More>> “Hey degen, are you stressed? Just let it all out,” he wrote, along with a link to join the group. The court said the defendant had also incited people to commit public nuisance, with messages calling on them to take part in rallies and demonstrations including at Hong Kong International Airport, to block roads and to paralyse the public transportation system. Various forms of protest promoted on the messaging platform included general strikes, lunchtime protests and silent sit-ins. Telegram offers a powerful toolset that allows businesses to create and manage channels, groups, and bots to broadcast messages, engage in conversations, and offer reliable customer support via bots.
from us


Telegram Python_Labs🐍
FROM American