new programming student here! I don't understand why this code returns "troy aikman has won 3" instead of "troy aikman has won3". There is no space after " has won" so I'm assuming it has to do with the ", len()" portion. I've switched the comma to "+" which gave me an error (as I thought it would). I haven't been able to find anything stating that len() automatically adds spaces so I've concluded that it has to be how the comma interacts with the len() function, but am confused as to how or why?
my_dict={
"name":"troy aikman",
"position":"qb",
"team":"dalls cowboys",
"age": 54,
"weight": 220.,
"superbowls":["XXVII","XXVIII","XXX"],
"awards":{
"super_bowl_mvp":"XXVII",
"probowl":[1991,1992,1993,1994,1995,1996],
"man_of_the_year":1997
}
}
print(
my_dict['name'] + " has won", len(my_dict['superbowls'])
)
In Python, the print
function prints each of the arguments specified, separated by a separator sep. The default value for sep is a space.
You are passing two arguments:
1: my_dict['name'] + " has won"
(which evaluates to "troy aikman has won")
2: len(my_dict['superbowls'])
(which evaluates to the number 3, whose string representation is "3")
So what prints is the first argument ("troy aikman has won"); the sep value (a space); and the second argument ("3"): "troy aikman has won 3"
Doc at https://docs.python.org/3/library/functions.html#print