This forum is now read-only. Please use our new forums! Go to forums
banner
Close banner
Very basic question: What does def do/mean?
What is def used for?
Answer 517521c2ae82f800c8001d2e
9 votes
def
is short for “define”. It’s a keyword that you need to define a function (aka method). All the code that you put between the def function_name(parameters)
and end
will be executed every time you call the function_name
later. Example:
def greet(person_name) # begin definition
puts "Hello, #{person_name}, nice to see you!"
end # end definition
greet("Alex") #=> Hello, Alex, nice to see you!
Answer 5190544552d35bc48f0009f0
Popular free courses
- Free Course
Learn SQL
In this SQL course, you'll learn how to manage large datasets and analyze real data using the standard data management language.Beginner friendly,4 LessonsLanguage Fluency - Free Course
Learn JavaScript
Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.Beginner friendly,11 LessonsLanguage Fluency - Free Course
Learn HTML
Start at the beginning by learning HTML basics — an important foundation for building and editing web pages.Beginner friendly,6 LessonsLanguage Fluency
3 comments
Very helpful and explanitory.
The whole second half of conditionals and control flow in Python is very poorly written. They never explicitly tell you what ‘def’ means.
def means define. defines a variable, or function. Define greet (person_name) The definition of greet is person_name