Skip to main content

Python Data Types and Type Conversion



Built-in Data Types

In programming, data type is an important concept.

Variables can store data of different types, and different types can do different things.

Python has the following data types built-in by default, in these categories:

Text Type:str
Numeric Types:intfloatcomplex
Sequence Types:listtuplerange
Mapping Type:dict
Set Types:setfrozenset
Boolean Type:bool
Binary Types:bytesbytearraymemoryview

Getting the Data Type

You can get the data type of any object by using the type() function:

Example

Print the data type of the variable x:



Type Conversion

You can convert from one type to another with the int()float(), and complex() methods:

Example

Convert from one type to another:


Comments

Popular posts from this blog

Building a Binary Calculator With Object Oriented Programming in Python

Let's begin! Creating a basic calculator is a no biggie! So we are applying the concept of object oriented programming and making this program work until the user ask to end the task, in this calculator we can also intake the value as much as we want without restarting the program! It's one of basis and yet a core project where majority of your programming skills are used! Happy Programming!

Dynamic List in Python

Even Captain America had a list! Why shouldn't we? 

Sign In and Sign Up with Python (Back-End)

Sign up to the awesomeness of this cool project and get yourself started!