Print and join statement in python

前端 未结 3 780
执念已碎
执念已碎 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:13

    Yes I second @jonrsharpe str is buit-in and use should not use that name.

    print " The join o/p is %s and The length is %s"%(s.join(seq),len(s.join(seq)))
    

    Here your length is not 3 it will be 5. Since you have added 2 '-'. If you want to count excluding '-' then use line below.

    print " The join o/p is %s and The length is %s"%(s.join(seq),len(s.join(seq).replace('-','')))
    

提交回复
热议问题