This forum is now read-only. Please use our new forums! Go to forums

banner
Close banner
0 points
Submitted by M E
almost 11 years

Very basic question: What does def do/mean?

What is def used for?

Answer 517521c2ae82f800c8001d2e

9 votes

Permalink

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!
points
Submitted by Alex J
almost 11 years

3 comments

alecguarino97 over 9 years

Very helpful and explanitory.

Austin Slack about 9 years

The whole second half of conditionals and control flow in Python is very poorly written. They never explicitly tell you what ‘def’ means.

alecguarino97 about 9 years

def means define. defines a variable, or function. Define greet (person_name) The definition of greet is person_name

Answer 5190544552d35bc48f0009f0

0 votes

Permalink

Its stands for definition

points
Submitted by JACQUELINE
almost 11 years