Print and join statement in python

前端 未结 3 745
执念已碎
执念已碎 2021-01-26 11:31

I am newbie to python. I have a sequence and I am able to print it using join method and able to print the length of the sequence separately. I am not able to print

3条回答
  •  心在旅途
    2021-01-26 12:17

    First of all, don't use str as a variable name. This is a built-in; using it as a variable name means you can't access it (e.g. to convert other items to strings).

    Secondly, I would recommend string formatting here:

    print "The join output is: {0}. The length is: {1}.".format("-".join(seq), 
                                                                len(seq))
    

提交回复
热议问题