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

Trending Topics

Online now

Members online
1,178
Guests online
5,100
Total visitors
6,278

Forum statistics

Threads
2,353,727
Posts
29,380,889
Members
1,081,124
Latest member
marviene
Back
Top