🔒 Closed Replace parenthesis

Status
Not open for further replies.

vien3211

Honorary Poster
Pa help naman po i replace ung parenthesis using python

Ganito po ung input: D / )C * B + A(

Dapat po maging ganito ung output: D / (C * B + A)
 
First, replace the first parenthesis then remove the last char then append closing parenthesis

Code:
>>> x = 'D / )C * B + A('
>>> y = x.replace(')', '(')[:-1] + ')'
>>> y
'D / (C * B + A)'
Hello sir! Ask ko lang po kung ito po ung ginamit niyo [:-1] para ma remove ung last char?
 
Status
Not open for further replies.

About this Thread

  • 4
    Replies
  • 724
    Views
  • 3
    Participants
Last reply from:
vien3211

Trending Topics

Online now

Members online
1,156
Guests online
2,917
Total visitors
4,073

Forum statistics

Threads
2,331,821
Posts
29,260,568
Members
1,147,835
Latest member
shsjsjkssksn
Back
Top