เริ่มต้นใช้งานเริ่มต้นใช้งานได้ฟรี

Lazy evaluation

เมื่อ Python รันสคริปต์ต่อไปนี้ทีละบรรทัด ข้อความ 'Converting to percentage' จะถูกพิมพ์ออกมาเมื่อถึงบรรทัดใด?

from dask import delayed

def fraction_to_percent(x):
     percentage = x * 100
     print('Converting to percentage')
     return x

frac = 0.3
percentage = delayed(fraction_to_percent)(frac)
computed_percentage = percentage.compute()

print(percentage)
print(computed_percentage)

สามารถใช้คอนโซลเพื่อช่วยหาคำตอบได้ ฟังก์ชัน fraction_to_percent() พร้อมใช้งานในเซสชันนี้แล้ว

แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร

Parallel Programming with Dask in Python

ดูคอร์ส

แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำจริง

เปลี่ยนทฤษฎีให้เป็นการลงมือทำด้วยแบบฝึกหัดเชิงโต้ตอบหนึ่งในของเรา

เริ่มแบบฝึกหัด