6Functions

Functions - Basically it means to do something, as an example we can create a function to read files, update files, update our users. Literally anything. In Python there are two types of Functions

  • Predefined Function - Predefined functions are available in Python by default, example: len()

  • Created Function - Our created functions, this is where we can create a function to do whatever we would like it to do.

  • For anything there isn't a predefined function, we need to code it ourselves.


Predefined Function:

text = input("Enter text: ")

print(len(text))
circle-info

len() is a predefined function - It returns the length of a string/text.


Created Function:

def say_hello():
    print("Hello, world!")

# Loop to repeat the function twice
for _ in range(2):
    say_hello()

Last updated