top of page

Python Built-in Functions

The most popular function in Python is print()This function has other cousins that are built-in the platform.

Input() Function

Input() function is a simple way to prompt the user for some input (such as provide their name). All user input is stored as a string.

​

Code Input:

​

name input("Hi! What's your name?")

print("Nice to meet you " + name + "!")

​

Code Output:

​

Hi! What's your name?

Nice to meet you, Jim!

Len() Function

Len() function helps you find the length of any string, list, tuple, dictionary, or another data type. It is a handy command to determine excessive values and trim them to optimize the perrformance of your program.

​

Code Input for a string:

​

# testing len()

str1 "Hope you are enjoying the tutorial!"

print("The length of the string is : ", len(str1))

​

Code Output:

​

The length of the string is: 35

Filter()

Filter() function is used to exclude items in an iterable object (tuples, lists, etc)

​

ages [5, 12, 17, 18, 24, 32]

​

def myFunc (x):

      if x < 18

          return False

      else:

          return True

 

adults = filter(myFunc, ages)

​

for in adults

    print(x)

​

​

bottom of page