Get Started

Familiar functions

Out of the box, Python offers a bunch of built-in functions to make your life as a data scientist easier. You already know two such functions: print() and type(). There are also functions like str(), int(), bool() and float() to switch between data types. You can find out about them here. These are built-in functions as well.

Calling a function is easy. To get the type of 3.0 and store the output as a new variable, result, you can use the following:

result = type(3.0)

This is a part of the course

“Introduction to Python”

View Course

Exercise instructions

  • Use print() in combination with type() to print out the type of var1.
  • Use len() to get the length of the list var1. Wrap it in a print() call to directly print it out.
  • Use int() to convert var2 to an integer. Store the output as out2.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Create variables var1 and var2
var1 = [1, 2, 3, 4]
var2 = True

# Print out type of var1
____

# Print out length of var1
____

# Convert var2 to an integer: out2
out2 = ____

This exercise is part of the course

Introduction to Python

BeginnerSkill Level
4.8+
2379 reviews

Master the basics of data analysis with Python in just four hours. This online course will introduce the Python interface and explore popular packages.

You'll learn how to use functions, methods, and packages to efficiently leverage the code that brilliant Python developers have written. The goal is to reduce the amount of code you need to solve challenging problems!

Exercise 1: FunctionsExercise 2: Familiar functions
Exercise 3: Help!Exercise 4: Multiple argumentsExercise 5: MethodsExercise 6: String MethodsExercise 7: List MethodsExercise 8: List Methods (2)Exercise 9: PackagesExercise 10: Import packageExercise 11: Selective importExercise 12: Different ways of importing

What is DataCamp?

Learn the data skills you need online at your own pace—from non-coding essentials to data science and machine learning.

Start Learning for Free