Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
たとえば、turn 45 を turn(45) に変換するにはどうすればよいですか? または、一般的に Python で AnyValue を逆にして (AnyValue) を逆にしますか?
ユーザー入力は次のようになります。
reverse 45
そして、出力は次のようになります。
reverse(45)
正規表現を使用して、数字の周りに括弧を追加できます。
import re s = "reverse 45" output = re.sub(r'reverse (\d+)', r'reverse(\1)', s)
python 3.2 a = reverse 45 a.replace(" ","(") + ")"