Question: Recently I have started learning python programming language and I got stuck while printing 123..n sequence using this:

```
n=10
print(i for i in range(1,n+1))

```

I got this output:

```
<generator object <genexpr> at 0x7f5990f20db0>                                   

```

Expecting Output:  

 1234....n  

 (Note: Only continuous output)

Answer: 
This line:

```
print(i for i in range(1, n+1))

```

Creates a generator and prints it out, it's exactly what's expected. To print the values as a `list`, which i'm guessing is what you intended, add `[]`:

```
print([i for i in range(1, n+1)])

```

If you intended to print each element on a separate line the syntax is similar but slightly modified:

```
[print(i) for i in range(1, n+1)]

```

EDIT: For everything on the same line as you requested in your comment:

```
print(''.join(str(i) for i in range(1, n+1)))

```
As many have mentioned this is creating a `generator`. Generators are different from normal functions. Generator returns an `iterator` which you can iterate one item per iteration.

The method that uses `yield` statement returns a generator.
Difference between return statement and yield is, that `return` statement terminates the program completely. Whereas `yield` statement saves the state of the variable for the next iterations. Suppose you want to do something with the yielded value in those scenarios we use generators.

Following are the examples for return and yield statement.

`Return`

```
def retutn_meth(n):
    for i in range(1, n+1):
        return i

a = retutn_meth(10)
for b in range(1,10):
    print(a)

```

`Output`

```
1
1
1
1
1
1
1
1
1

Process finished with exit code 0

```

`yield`

```
def gen_meth(n):
    for i in range(1, n+1):
        yield i

a = gen_meth(10)
for b in range(1,10):
    print(next(a))
    print('blah blah blah')

```

`output`

```
1
blah blah blah
2
blah blah blah
3
blah blah blah
4
blah blah blah
5
blah blah blah
6
blah blah blah
7
blah blah blah
8
blah blah blah
9
blah blah blah

Process finished with exit code 0

```

As you can see in the second example the state of the variable has been saved in each iteration and at `print('blah blah') you can put any other functionality you want to do in between the iterations.

Please read here for further clarification: [Python Generators](https://www.programiz.com/python-programming/generator)