-3
def get_formatted_text(first,last):
  full_name=(f'{first} {last}').title()
  return full_name #only works with print. Why?

get_formatted_text('Dick','Long')

I don't see any output in my terminal when I do the function call. It works with print function, but I don't understand why print is needed when return will show the output?

3 Answers3

2

Return will not print the value. It only 'returns' it. When coding directly in the Python terminal it will print the value, but that is the extra capabilities of the terminal, not the return. In all other instances, print is needed to output to the terminal.

Ismail Hafeez
  • 730
  • 3
  • 10
1

its just RETURNING the value its up to u what u do with the value and the the brackets r also not required if u r returning the value

def get_formatted_text(first, last):
    full_name = f'{first} {last}'.title()
    return full_name  # only works with print. Why?


x = get_formatted_text('Dick', 'Long')
print(x)

But if u r returning a value u can even manuplitate like

def get_formatted_text(first, last):
     full_name = f'{first} {last}'.title()
     return full_name  # only works with print. Why?


 x = get_formatted_text('Dick', 'Long')
 print(x.lower())
MrHola21
  • 301
  • 2
  • 8
0

Your return statement returns the title case string. It does not print the element in the console.

After getting the formatted text you may update it as necessary.

def get_formatted_text(first,last):
  full_name=(f'{first} {last}').title()
  return full_name

formatted_text = get_formatted_text('john','doe')
print(f"Formatted text with title case: {formatted_text}")

Output:

Formatted text with title case: John Doe

Reference:

arshovon
  • 13,270
  • 9
  • 51
  • 69