one can print values using the format method in python. This small example will help
take input of two numbers a and b. Print a+b in first line and a-b in second line
print('{:d}\n{:d}'.format(a+b,a-b))
Similarly in the answer we can do
print ("{0}. {1} appears {2} times.".format(22, 'c', 9999))
The python method format() for string is used to specify a string format. So {0},{1},{2} are like array indexes called as positional parameters. Therefore {0} is assigned first value written in format (a+b), {1} is assigned the second value (a-b) and so on. We can also use keyword instead of positional parameter like for example
print("Hi! my name is {name}".format(name="rashi"))
Therefore name here is the keyword and its value is Rashi
Hope it helps :)
print()
is a function in Python 3, not a statement. Surround everything in your last line (except the wordprint
) in parentheses and you'll be all set.print(....)
, which will returnNone
, thenNone % (one, two, three_strings)
. You want thesomething % (one, two, three_strings)
to be done inside theprint(....)
call.