PYTHOPIACHANNEL Telegram 144
وقتی یک متغیر رو به تابع پاس میدیم، آیا مقدارش تغییر میکنه؟ بستگی به نوع متغیر داره

۱. داده‌های تغییرناپذیر (Immutable)

این داده‌ها مثل اعداد (int) و متن‌ها (str)، وقتی به تابع فرستاده بشن، فقط یک کپی از مقدارشون میره. پس متغیر اصلی تغییر نمی‌کنه.

def try_to_change(money):
money = 1000
# فقط روی کپی اثر داره

my_money = 50
try_to_change(my_money)
print(my_money)

# خروجی: 50

(بدون تغییر)


۲. داده‌های تغییرپذیر (Mutable)

این‌ها مثل لیست‌ها (list) و دیکشنری‌ها (dict) به صورت اشتراکی به تابع داده می‌شن. پس اگه تابع تغییری بده، متغیر اصلی هم تغییر می‌کنه!

def add_to_list(items):
items.append("شیر")
# روی لیست اصلی اثر می‌ذاره

shopping_list = ["نان", "پنیر"]
add_to_list(shopping_list)
print(shopping_list)

# خروجی: ['نان', 'پنیر', 'شیر']
(تغییر کرد)

نکته کلیدی: حواستون به لیست‌ها و دیکشنری‌ها باشه! چون توابع می‌تونن محتویات اون‌ها رو برای همیشه عوض کنن.
1🔥15👍3



tgoop.com/pythopiachannel/144
Create:
Last Update:

وقتی یک متغیر رو به تابع پاس میدیم، آیا مقدارش تغییر میکنه؟ بستگی به نوع متغیر داره

۱. داده‌های تغییرناپذیر (Immutable)

این داده‌ها مثل اعداد (int) و متن‌ها (str)، وقتی به تابع فرستاده بشن، فقط یک کپی از مقدارشون میره. پس متغیر اصلی تغییر نمی‌کنه.

def try_to_change(money):
money = 1000
# فقط روی کپی اثر داره

my_money = 50
try_to_change(my_money)
print(my_money)

# خروجی: 50

(بدون تغییر)


۲. داده‌های تغییرپذیر (Mutable)

این‌ها مثل لیست‌ها (list) و دیکشنری‌ها (dict) به صورت اشتراکی به تابع داده می‌شن. پس اگه تابع تغییری بده، متغیر اصلی هم تغییر می‌کنه!

def add_to_list(items):
items.append("شیر")
# روی لیست اصلی اثر می‌ذاره

shopping_list = ["نان", "پنیر"]
add_to_list(shopping_list)
print(shopping_list)

# خروجی: ['نان', 'پنیر', 'شیر']
(تغییر کرد)

نکته کلیدی: حواستون به لیست‌ها و دیکشنری‌ها باشه! چون توابع می‌تونن محتویات اون‌ها رو برای همیشه عوض کنن.

BY Pythopia




Share with your friend now:
tgoop.com/pythopiachannel/144

View MORE
Open in Telegram


Telegram News

Date: |

Other crimes that the SUCK Channel incited under Ng’s watch included using corrosive chemicals to make explosives and causing grievous bodily harm with intent. The court also found Ng responsible for calling on people to assist protesters who clashed violently with police at several universities in November 2019. You can invite up to 200 people from your contacts to join your channel as the next step. Select the users you want to add and click “Invite.” You can skip this step altogether. Healing through screaming therapy Your posting frequency depends on the topic of your channel. If you have a news channel, it’s OK to publish new content every day (or even every hour). For other industries, stick with 2-3 large posts a week. The visual aspect of channels is very critical. In fact, design is the first thing that a potential subscriber pays attention to, even though unconsciously.
from us


Telegram Pythopia
FROM American