(Python-3): Why is the str() function behaving weirdly?

def stringer(x):
    str(object=x)
    alpha = 'objs['+x+']'
    return alpha

I just ran a sample query to check a part of my code here:

print stringer(3)

and I get a response that str and int cannot be concatenated. I have tried it with this snippet code too and get the same error.:

def stringer(x):
    str(x)
    alpha = 'objs['+x+']'
    return alpha

what is wrong with my code?
thank you :slight_smile:
http://srujanmhase.github.io

Are you only trying to concatenate? Iā€™d suggest the following code:

def stringer(x):
    return "objs[%d]" % (x)

print stringer(3)

Clean and concise - pythonic!