```
table_name='Customer$'
if table_name.startswith('$'):
    table_name=table_name[1:]
if table_name.endswith('$'):
    table_name=table_name[:-1]

```

I tried with the above code it gives me correct result as

```
 Customer

```

Is there any optimized way of doing it? please reply
['https://Stackoverflow.com/questions/63154860', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/13818054/']
Use `.strip()`:

```
table_name = '$Customer$'.strip('$')

```

This will remove all `$`s from the start and end and do nothing if there aren't dollars surrounding the string.
```
'$Customer$'.strip('$')

```

`strip()` method removes any leading (spaces at the beginning) and trailing (spaces at the end) characters (space is the default leading character to remove). By default trailing and leading spaces are removed. If an argument of character/s should be removed has been passed, then that character/s will be removed from leading and trailing poistions