Question: I want to be able to add an attribute to a dictionary but only if the condition I pass in is true. For example: 

```
def addSum(num):
    obj = {
             'name': "Home",
              'url': "/",
              num > 0 ? 'data': num
    }

```

Is this possible? I can't find a way to do this in python, I have only seen examples in javascript.

Answer: 
You can't do it with quite that syntax. For one thing, you need Python, not Java/C.

(1) add the attribute, but set to `None`:

```
obj = {'name': "Home",
       'url': "/",
       'data': num if num > 0 else None
      }

```

(2) make it an add-on:

```
obj = {'name': "Home",
       'url': "/"}
if num > 0:
    obj['data'] = num

```
Yes, just create the dictionary without the attribute, then create an if statement to add it if the condition is true:

```
def addSum(num):
    obj = {
          'name': "Home",
          'url': "/",      
    }
    if num > 0:
        obj['data'] = num

    return obj

```