Question: For the given file path:

```
source_path = 'User/animal/herbivore/query/{}/'

```

If the value is Null It should be formatted as follows

```
'User/animal/herbivore/query/Q1'

```

If the value is a number it should be

```
'User/animal/herbivore/query/1/Q1'

```

How do I format the source\_path when the value is null

Answer: 
```
source_path = 'User/animal/herbivore/query/'
end_path = 'Q1'
str_value = ''

if str_value:
    if type(str_value) == int or (type(str_value) == str and str_value.isdigit()):
        resulted_path = source_path + str(str_value) + '/' + end_path
        print(resulted_path)
else:
    resulted_path = source_path + end_path
    print(resulted_path)

# output
# case 1 :
# str_value = ''
# resulted_path = 'User/animal/herbivore/query/Q1'

# case 2 :
# str_value = '1'
# resulted_path = 'User/animal/herbivore/query/1/Q1'

# case 3 :
# str_value = 1
# resulted_path = 'User/animal/herbivore/query/1/Q1'

# case 4 :
# str_value = None
# resulted_path = 'User/animal/herbivore/query/Q1'

```

You can optimize your code further by removing if conditions which you don't need. Also you can add other conditional logic if required.
I think you should use if else here.
If the value is Null, it should be formatted as :-
'User/animal/herbivore/query/Q1'

else the value is 1, then it should be formatted as :-
'User/animal/herbivore/query/1/Q1'