Web Microsoft 365 ◉ 7 views Dynamic Array

=PY()

PY function

Applies To: Excel for Microsoft 365Excel for Microsoft 365 for Mac
=PY(python_code,return_type)
Hover argument names in the table for details.
Output typeText
Popularity15 / 100
VolatileNo
Dynamic ArrayYes
📥 Download sample .xlsx — Coming soon ▦ Try in Playground Dedicated file for this function — safe & lightweight · sample data + live formulas
Share:

⬇ Download Sample Workbook

A dedicated .xlsx for =PY() with Persian sample data & live formulas — open in Excel and practice.

  • Sheet “Sample” — data table + formula in place
  • Sheet “Guide” — syntax, arguments & tips from this page
  • Instant & secure (token + rate limit)
📥 Download PY.xlsx — Coming soon ~ 8–12 KB · No macros

⇪ Share

Send this function to friends

🧠 🧠 Quiz this function

%d questions — syntax, example & errors — test yourself!

◧ Arguments

ArgumentTypeRequiredDescription
python_code Text Required The Python code to run on a secure Microsoft Cloud runtime. Must be static text.
return_type Number Required Specify the desired return type. Must be a static number 0 or 1.0 indicates Excel value.1 indicates Python object.

▣ Examples

الحاق دو رشته متنی در پایتون. =PY('Hello' + ' ' + 'World',0)
خواندن جدول Table1 با سرآیندها به عنوان شیء پایتون. =PY("xl(""Table1[#All]"", headers=True)",1)

✦ Tips

  • The PY function cannot be directly entered or seen from Excel's formula bar, instead the Python editor will generate it and insert it into the cell for you. The PY function syntax is primarily used by add-ins to directly insert or read Python formulas. It can also be seen when using the FORMULATEXT function on a cell containing a Python formula.
  • The PY function can be seen by FORMULATEXT and written and read by add-ins.
  • The PY function is not visible in the formula bar as it is displayed using the Python editor.
  • The PY function cannot be used with any other Excel functions. If used with other functions, a formula cannot be entered.
  • Both the python_code and return_type arguments must be static.

💬 Comments & Q&A 0 approved

🔒 Your comment will be published after review.

Share your thoughts — visible after admin approval

No comments yet — be the first!

✍️ Add comment / question

captcha
🔒 Your comment will be published after review.