🔒 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
  • 710
    Views
  • 3
    Participants
Last reply from:
vien3211

Trending Topics

Online now

Members online
643
Guests online
1,367
Total visitors
2,010

Forum statistics

Threads
2,292,935
Posts
29,080,218
Members
1,209,592
Latest member
jacoopal99
Back
Top