g | x | w | all
Bytes Lang Time Link
035Python 2240925T045015ZInertial
046PowerShell231110T104513ZMark Har
036Python231108T163451Zbsoelch
035Python 3231108T173507ZJonathan

Python 2, 35 bytes

print"("+s[:3]+")",s[3:6]+"-"+s[6:]

Simply reduces the second solution of this answer by 2 bytes, since in Python 2 print would be a statement, not a function.

PowerShell, 46 bytes

"($($a[0..2])) $($a[3..5])-$($a[6..9])"-join''

Try it online!

The output is a little weird, if someone can suggest a fix to that it would be much appreciated!

Python, 36 bytes

slightly improved version of your f-string (see also Jonathan Allan's comment), wrapped in a function

print(f"({s[:3]}) {s[3:6]}-{s[6:]}")

Attempt This Online!


Python, 37 bytes

without format strings

print("("+s[:3]+")",s[3:6]+"-"+s[6:])

Attempt This Online!

uses that print inserts a space between arguments


Python, 39 bytes

C-style format string

print("(%s%s%s) %s%s%s-%s%s%s%s"%(*s,))

Attempt This Online!

printing characters separately is slightly shorter than spiting string in 3 parts

Python 3, 35 bytes

print(f"({s:.3}) {s[3:6]}-{s[6:]}")

Try it online!

Uses the solution from the question but saves three bytes:

  1. removes a redundant : in the final slice s[6::], and
  2. uses the precision specifier (.) of the format_spec (the bit after the : in {...:...}) which is overloaded for string types to give a prefix so {s[0:3]} -> {s[:3]} -> {s:.3}