Question: The following Python code is what I have already tried in field calculator of ArcMap 10.5.1:

Pre-Logic Script Code:

```
def ConcatAddr(!JOIN_KEY!)
      val = ""
          if !Address! <> val
              return !Address! + " "
          else
              return val
          if !StreetName! <> val
              return !StreetName! + " "
          else
              return val
          if !Apartment! <> val
              return !Apartment! + " "
          else
              return val
          if !CityCode! <> val
              return !CityCode! + " "
          else
              return val
          if !ZipCode! <> val
              return !ZipCode! + " "
          else
              return val

JOIN_KEY =
ConcatAddr(!JOIN_KEY!)

```

Answer: 
```
def ConcatAddr(Adress,Streetname,Apartment,Citycode,Zipcode):
    return ' '.join([str(i) for i in [Adress,Streetname,Apartment,Citycode,Zipcode] if i not in(None,' ')])

```

Use Python parser and call with

JOIN\_KEY=

```
ConcatAddr(!Adress!,!Streetname!,!Apartment!,!Citycode!,!Zipcode!)

```

(You can also define the function as:

```
def ConcatAddr(*args):
    return ' '.join([str(i) for i in args if i not in(None,' ')])

```

and it will take any number of inputs)
Rewrite your function to this:

```
def ConcatAddr(!JOIN_KEY!)
    vals = []
    vals.append(!Address!)
    vals.append(!StreetName!)
    vals.append(!Apartment!)
    vals.append(!CityCode!)
    vals.append(!ZipCode!)
    nvals = [x for x in vals if x <> '' and x <> None]
    return " ".join(nvals)

```