Question: I'm not able to remove the spacing in a `for`-loop as numbers are not coming in the same for making the pattern.

My code:

```
for i in range(1,5):
    for j in range(1,i):
       print(j)

```

Produces the following result:

```
1
1
2
1
2
3

```

But my desired output is:

```
1
12
123
1234

```

Answer: 
Try this:

```
print(j, end='')

```

`end` by default is `\n` (see [`print()`](http://docs.python.org/3/library/functions.html#print)). Also, be sure to print a newline at the end of each outer loop iteration:

```
for i in range(1,6):  # notice that I changed this to 6
    for j in range(1,i):
        print(j, end='')  # added end=''
    print()  # printing newline here

```

```

1
12
123
1234

```

---

**EDIT** I just noticed you were using Python 2.7. Since that's the case, you can use `print j,` instead of `print(j, end='')` and `print` instead of `print()`. Note that `print j,` will leave spaces between the `j`s. If you don't want this, you can `import sys` and use `sys.stdout.write(j)` instead (see [`sys`](http://docs.python.org/2/library/sys.html)).

Furthermore, if you want to use the Python 3 print function as shown above, you can always

```
from __future__ import print_function

```
I thought the idea of @Shiva was really nice and made a slightly more general pyramid function, maybe someone can use/enjoy it it:

```py
def pyramid(n_rows, s, upside_down=False, offset=0):
    whites = ' ' * len(s)
    offset = ' ' * offset

    indices = np.arange(n_rows)

    if upside_down:
        indices = zip(indices[::-1]+1, indices)
    else:
        indices = zip(indices+1, indices[::-1])

    for i, j  in indices:
        print(f"{offset + whites * j}{(s + whites) * i}")

pyramid(4, 'SO')
#       SO  
#     SO  SO  
#   SO  SO  SO  
# SO  SO  SO  SO  

pyramid(4, '*', upside_down=True, offset=3)
#    * * * * 
#     * * * 
#      * * 
#       * 

```