Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

How to define a function in python?

def main():
#this will define your function, which you can use in the program
#or you can use it in other programs too, which ill show later
#also you have to call your function once atleast
	userinput = input("String: ")
    #ask the user for input, which is being stored in userinput
    if len(userinput) < 5:
    	print("it is longer")
    else: 
    	print("it is shorter")
main()
#this will call the function
'''
to use your function in other programs, you can just do the following
from (the name of the program you want to import the function from) import (function name)
done!

Really hoped this helped
'''
Source by www.py4e.com #
 
PREVIOUS NEXT
Tagged: #How #define #function
ADD COMMENT
Topic
Name
3+1 =