Creating a new function in visual studio (original) (raw)
Hello, i’m trying to create a new function with DEF but the terminal just returns the path of the file but it doesn’t print. Can someone please help?
def greet(name):
print(f"hello, {name} !")
That just defines a function. You actually have to call the function to use it:
def greet(name):
print(f"hello, {name} !")
greet("jefink")
See https://python.swaroopch.com/functions.html or https://automatetheboringstuff.com/2e/chapter3/ for an explanation and examples.
jefink (Jeff) July 30, 2024, 1:47am 3
Hey thank you, I tried it but it doesn’t print it out in the terminal It just keeps showing the path location of the file. i’m using visual studio code on the Mac
Can you show a screenshot of what you see?
jefink (Jeff)
July 30, 2024, 4:38am 5
dirn (Andy Dirnberger) July 30, 2024, 1:25pm 6
You are calling say_hello
from inside itself. You need to remove the indentation from the line that calls it, like in the example provided by doomsdaychicken.