Format() in Server Script?

I’m trying to write a Server Script that will populated a few hidden fields with different number formats.

I get the error NameError: name ‘format’ is not defined with the following script

def phone_format(n):
    return format(int(n[:-1]), ",").replace(",", "-") + n[-1]   
doc.phone_e164 = phone_format(doc.phone)

However, the script below does work as intended, so I’m assuming it’s the improper/unsupported use of the format() function.

def phone_format(n):
    return n
doc.phone_e164 = phone_format(doc.phone)

Use f-strings instead?

I noticed this weekend that “+=” (with partial strings) also doesn’t work in ServerScript.
But adding them normally like “completestring = completestring + newpart” just works.