Data Types in Python

Astha Chauhan
2 min readJul 31, 2021

--

Hi there!

This blog is inspired by Python Basics for Data Science course EDX by IBM.

Let’s start this journey by first knowing some widely used data types in Python:

  1. Integer denoted as int, there is a finite range of integers but it is quite large such as,

…….-3, -2, -1, 0, 1, 2, 3, …..

2. Float denoted as float, includes real numbers for eg,

…….-0.3, -0.2, -0.1, 0.0, 0.1, 0.2, 0.3……

3. String denoted as str is a sequence of characters and it takes values like:

“hello world ” , ‘hello world’

NOTE-> Strings can be written in both single as well as in double quotes.

We can also change one data type to another, this is called “typecasting” which are mainly of 3 types:

  • Int() : Int() function take float or string as an argument and return int type object.
  • float() : float() function take int or string as an argument and return float type object.
  • str() : str() function take float or int as an argument and return string type object.

For eg.

int(3.14):3

int(“4”): 4

str(1): “1”

str(1.1): “1”

float(2): 2.0

Boolean is another important type in Python, it can take on two values i.e. True or False.
Using the type command on a Boolean value, we obtain the term bool.
This is short for Boolean, if we cast a Boolean True to an integer or
float, we will get a 1.

i.e.

int(True)->1

int(False)->0

If we cast a Boolean False to an integer or float, we get a 0.
If we cast a 1 to a Boolean, we get a True.
Similarly, if we cast a 0 to a Boolean, we get a False.

i.e.

bool(1)-> True

bool(0)-> False

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Astha Chauhan
Astha Chauhan

Written by Astha Chauhan

Someone who believes in learning and sharing!

Responses (1)

Write a response