PY
py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# =============================================
#
# Difference between print() & return
#
# =============================================
# ============== Basic Print ==================
# when you print a value, it's pushed to the standard output (the ide, interpreter, whatever you're working on).
print("Regular print()")
# ============== Basic Return =================
# when you return a value (or values), it's not printed. when you see "return <something>" in a function, that means the function is fruitful, or that if you set a variable equal to the function, the variable will have the value that the function returns.
def fill_with_5():
"""Returns 5"""
return 5
x = 0
print("\nx before:",x)
# notice how print() isnt used on line 18, but only to show what the value was after on line 19
x = fill_with_5() # <-- function == 5
print("x now:",x)
# == Why we don't print functions that print ==
def bad_func(x):
"""PRINTS a number times 2"""
x = x*2
print(x,"(Inside Function)")
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run