دالة Python exec ()
مثال
تنفيذ كتلة من التعليمات البرمجية:
x = 'name
= "John"\nprint(name)'
exec(x)
التعريف والاستخدام
تقوم exec()
الوظيفة بتنفيذ كود بايثون المحدد.
تقبل الوظيفة exec()
كتلًا كبيرة من التعليمات البرمجية ، على عكس eval()
الوظيفة التي تقبل تعبيرًا واحدًا فقط
بناء الجملة
exec(object, globals, locals)
قيمه المعامل
Parameter | Description |
---|---|
object | A String, or a code object |
globals | Optional. A dictionary containing global parameters |
locals | Optional. A dictionary containing local parameters |