Functions
Functions/Methods in Computer Programming
# Define a function in Python
def greet(name):
return f"Hello, {name}!"
# Call the function
print(greet("Alice"))Hello, Alice!using System;
class Program
{
// Define a method in C#
static string Greet(string name)
{
return $"Hello, {name}!";
}
static void Main(string[] args)
{
// Call the method
Console.WriteLine(Greet("Bob"));
}
}Last updated
Was this helpful?