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

Trending Topics

Online now

Members online
1,221
Guests online
3,946
Total visitors
5,167

Forum statistics

Threads
2,308,349
Posts
29,184,599
Members
1,191,945
Latest member
Ahehuho
Back
Top