-4
def empty(new):
    new1=''
    for i in new:
        new1=i+new1
        print(new1)
    print(new1)    

new='First question'
print(new)
print(empty(new))

output:

First question
F
iF
riF
sriF
tsriF
 tsriF
q tsriF
uq tsriF
euq tsriF
seuq tsriF
tseuq tsriF
itseuq tsriF
oitseuq tsriF
noitseuq tsriF
noitseuq tsriF
None

Question: why do i get none at the end???

Austin
  • 25,759
  • 4
  • 25
  • 48

2 Answers2

0

I think what you want is to replace print(empty(new)) with empty(new). In the first case you are printing the return value of the call to the function empty, which in this case is None because the function doesn't have a return statement.

Christian Callau
  • 960
  • 6
  • 11
0

You can either add a return to the function:

def empty(new):
    new1=''
    for i in new:
        new1=i+new1
        print(new1)
    return new1   

new='First question'
print(new)
print(empty(new))

Or call function not in print:

def empty(new):
    new1=''
    for i in new:
        new1=i+new1
        print(new1)
    print(new1)  

new='First question'
print(new)
empty(new)
Rarblack
  • 4,559
  • 4
  • 22
  • 33