Skip to main content
It looks like you're using Internet Explorer 11 or older. This website works best with modern browsers such as the latest versions of Chrome, Firefox, Safari, and Edge. If you continue with this browser, you may see unexpected results.

Python for Basic Data Analysis: 1.3 Data types

Get started on your learning journey towards data science using Python. Equip yourself with practical skills in Python programming for the purpose of basic data manipulation and analysis.

Data Types

Data types 

Data types are the classification of data items. Data types represents a kind of value which determines what can be done to that data.


What are the different types of data in Python?

Data Types Examples Explanation Mutable/Immutable?
Strings "Hello!", "23.34" Text - anything between
" "  becomes string
Immutable
Integers 5364 Whole numbers Immutable
Floats 3.1415 Decimal Numbers Immutable
Booleans True, False Truth values that represent Yes/No Immutable
Lists [1,2,3,4,5] A collection of data,
sits between  [ ]  
Mutable
Tuples (1,2,3,4,5) A collection of data,
sits between  ( )  
Immutable
Dictionaries {"a":1, "b":2, "c":3} A collection of data, 
sits between  { }  
Mutable

How do you set data types?

Data types are set when you assign a value to a variable.

Examples Type Explanation
ex_1 = "Hello World" string The data assigned sits in between  " " 
ex_2 = 254 integer The data assigned does not sit in between  " " , and is a whole number
ex_3 = 25.43 float The data assigned does not sit in between  " " , and is a decimal number
ex_4 = ["Anna", "Bella", "Cora"] list A list of strings - Data assigned sits in between  " " , within  [ ]  

How do you check data types?

Use the  type( )  function to check data types.

 type(x)  determines and returns what is the type of the input x


Click the triangle button to run the codes and see the output:

Type conversion

To convert variables from one type to another (i.e. integers to floats), we use type conversions as follows:

Data Type Syntax
strings str()
integer int()
floats float()
lists list()


Application

Exercises

1. Determine and print the type of the following variables

  • variable1 = 123
  • variable2 = "123"
  • variable3 = 123.456


2. Convert the following variables print the result

  • Convert this float into an integer
    • variable4 = 23.0
  • Convert this string into an integer
    • variable5 = "6000"