Return
and print
are entirely different things.
Return doesn't "print" anything.
You cannot replace "print" statements with "return".
When your function reaches a return statement, it will end the function.
That is what "return" means.
It returns back to the calling scope.
Do you understand the output of your program?
It prints
CSNone
GITNone
In your current code, you could say:
get_capitals("CS1301")
print()
get_capitals("Georgia Institute of Technology")
This will result in
CS
GIT
The single print()
statement gives you a convenient newline.
It's the function call that prints out cs
and GIT
, not your surrounding print
statement.
Your print statements only prints the return-value of the function, and because your function doesn't return anything, it adds a None
to the output generated by the function call.
If you want to use a return in the function and do not want to use print() inside the function, then you have to compose the return value of the function at the places where you use print() at the moment.
You compose the return string at these places and return the composed value with a return statement.
Then it makes sense to use
``print(get_capitals("CS1301"))```
the return-value of the function, which would then be defined, with print().
Play around with it a bit, then you will understand what happens.