Python 3 – Learn it quick – DataTypes

DataTypes in Python

In Python there are 8 basic data types namely integers, floating point, strings, lists, dictionaries, tuples, sets and Boolean.

The integer is represented using int and they are whole numbers, like 23, 60 etc.

The Floating point data types or Floats are represented using float, and are fractional numbers like 3.17, 56.78 etc.

The strings are represented using str and they are a string of characters, like a letter, group of letters or a backslash. Python recognises single and double quotes as the same thing, the beginning and end of the strings.

Example :

 “This is a string” 

Lists are represented by list and they are containers for holding the values.

Example :

names = ['joseph','nas', 'jas','ram'] 

Dictionary is represented by dict and they are unordered key value pairs.

Example :

 dictionary = { key1:value1, key2:value2, …}

Tuples are represented by tup and they are immutable sequence of objects.

Example :

 (78,”apple”,99.23)

Sets are represented by set and they are a collection which are unordered and unindexed.

Example :

{“str1″,”str2”}

Boolean are represented by bool and they represent logical value.

Example :

True/False
DataType Represented By Value Description
Integer int 24 Whole number values
Float float 45.89 Decimal numbers
String str “this is a sample string” Sequence of characters
List list [‘pencil’,’ink’,’paper’] Ordered sequence of objects
Dictionary dict {‘grapes’: ‘orange’,’apple’: ‘banana’} Unordered key value pairs
Tuples tup (24,”orange”,89.62) It is an immutable sequence of objects
Sets set {“str1″,”str2”} It is a collection which is unordered and unindexed
Boolean bool True/False Logical value

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.