Telegram Group & Telegram Channel
پایتونیک، روشی برای کوتاه کردن و خوانا کردن کدها
پایتون زبان بسیار قدرتمندی است و تقریبا هر برنامه ای می توان با آن نوشت. اما قدرت پایتون در ساده نویسی و کوتاه کردن دستورات برنامه است.
فرض کنید می خواهیم برنامه ای بنویسیم که اعداد زوج مابین 0 تا 100 را با یکدیگر جمع کند. ساختار برنامه نویسی چیزی شبیه زیر خواهد بود:
total=0
for i in range(1,100):
if i%2==0:
total+= i
print(total)
اگر بخواهیم کمی کد فوق را خلاصه کنیم از ساختار زیر هم می توانیم استفاده کنیم:
total=0
for i in range(1,100):
total+= i if i%2==0 else 0
print(total)

اما تمام کدهای فوق را می توانیم با یک خط زیر عوض کنیم:
print(sum(i if i%2==0 else 0 for i in range(1,100)))

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

#پایتون_مالی
#پایتونیک

#مقدمات
پایتون برای مالی در تلگرام https://www.tg-me.com/ar/Python4Finance/com.python4finance
پایتون برای مالی در بله https://ble.im/ar/Python4Finance/com.python4finance



tg-me.com/python4finance/44
Create:
Last Update:

پایتونیک، روشی برای کوتاه کردن و خوانا کردن کدها
پایتون زبان بسیار قدرتمندی است و تقریبا هر برنامه ای می توان با آن نوشت. اما قدرت پایتون در ساده نویسی و کوتاه کردن دستورات برنامه است.
فرض کنید می خواهیم برنامه ای بنویسیم که اعداد زوج مابین 0 تا 100 را با یکدیگر جمع کند. ساختار برنامه نویسی چیزی شبیه زیر خواهد بود:
total=0
for i in range(1,100):
if i%2==0:
total+= i
print(total)
اگر بخواهیم کمی کد فوق را خلاصه کنیم از ساختار زیر هم می توانیم استفاده کنیم:
total=0
for i in range(1,100):
total+= i if i%2==0 else 0
print(total)

اما تمام کدهای فوق را می توانیم با یک خط زیر عوض کنیم:
print(sum(i if i%2==0 else 0 for i in range(1,100)))

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

#پایتون_مالی
#پایتونیک

#مقدمات
پایتون برای مالی در تلگرام https://www.tg-me.com/ar/Python4Finance/com.python4finance
پایتون برای مالی در بله https://ble.im/ar/Python4Finance/com.python4finance

BY Python4Finance




Share with your friend now:
tg-me.com/python4finance/44

View MORE
Open in Telegram


Python4Finance Telegram | DID YOU KNOW?

Date: |

The global forecast for the Asian markets is murky following recent volatility, with crude oil prices providing support in what has been an otherwise tough month. The European markets were down and the U.S. bourses were mixed and flat and the Asian markets figure to split the difference.The TSE finished modestly lower on Friday following losses from the financial shares and property stocks.For the day, the index sank 15.09 points or 0.49 percent to finish at 3,061.35 after trading between 3,057.84 and 3,089.78. Volume was 1.39 billion shares worth 1.30 billion Singapore dollars. There were 285 decliners and 184 gainers.

However, analysts are positive on the stock now. “We have seen a huge downside movement in the stock due to the central electricity regulatory commission’s (CERC) order that seems to be negative from 2014-15 onwards but we cannot take a linear negative view on the stock and further downside movement on the stock is unlikely. Currently stock is underpriced. Investors can bet on it for a longer horizon," said Vivek Gupta, director research at CapitalVia Global Research.

Python4Finance from ar


Telegram Python4Finance
FROM USA