Reputation:
One might be eager to send a string to the print method, is which consists of some dynamic parameters. Just assume that the final length of the very string argument should be printed by format method. what is the required approach for this aim?
code = int(input("Get the code: "))
name = "Anonymous"
number = 7
print("{0}'s number is {1} and the code is {2}. The final length of the string is {3}".format(name,num,code,?))
# ? = length of {0}'s number is {1} and the code is {2}. The final length of the string is {3}
Upvotes: 0
Views: 45
Reputation: 19264
Use len()
:
code = int(input("Get the code: "))
name = "Anonymous"
number = 7
print("{0}'s length is {1}".format("{0}'s number is {1} and the code is {2}. The final length of the string is {3}".format(name,number,code,len(name+str(number)+str(code))), len("{0}'s number is {1} and the code is {2}. The final length of the string is {3}".format(name,number,code,len(name+str(number)+str(code)))))
Upvotes: 0