Ask coding questions

← Back to all posts
def function in python
ROCKINGRAYQUAZA (94)

can anyone help me with def function in python ??
i have searched on web but couldn't understand properly so please help...

Answered by CoolJames1610 (775) [earned 5 cycles]
View Answer
Comments
hotnewtop
CoolJames1610 (775)

i can help you, what is the problem?

ROCKINGRAYQUAZA (94)

@CoolJames1610 I just want to detailed with some sort of example which could be understood as i am a begginer to python

CoolJames1610 (775)

Okay here @ROCKINGRAYQUAZA

def say_hello(name):
     print("Hello " + name)
say_hello("CoolJames") #"CoolJames" is the parameter that you want to pass into say_hello and the say_hello function will exceute (Hello CoolJames)
say_hello(input("What is your name? ")) #What ever the user inputs will act as the parameter, so if I typed in James, the program will output "Hello James"

# Note that functions have the be defined before you can use them. e.g.
'''
say_hello("Bob")
def say_hello(name):
WRONG
def say_hello(name)
say_hello("Bob")
RIGHT
'''

Hope this helped. If you want any more help please say :)

If this answer helped please mark it :D

ROCKINGRAYQUAZA (94)

just one more how can i find you again on repl.it

ROCKINGRAYQUAZA (94)

how can i find you again on repl.it if i have any further queries [email protected]

ROCKINGRAYQUAZA (94)

@CoolJames1610 how do you make such cool programs ,they are mind blowing

ROCKINGRAYQUAZA (94)

plz tell how you those awesome programs
@ROCKINGRAYQUAZA