Sitemap
Pavan kumar reddy

Pavan kumar reddy

DATA TYPES IN PYTHON

3 min readOct 12, 2023

--

PYTHON DATA TYPES

Data Types :

The purpose of Data Types in Python is that “To Store the inputs in the main memory of the computer by allocating sufficient amount of memory space”.

Numeric data type:

  • Numeric data type represents numeric data such as Integers,Floating point &Complex numbers

Integers:

  • Integers are represented by int class
  • The purpose of int data type is that “ To store Integer Data OR Integral Value OR Whole Numbers (Numbers without Decimal Places)”.
  • Can be negative or postive numbers
  • In python ,Integers can be any length

Floating Point:

  • Float contains both integer and fractional part
  • The purpose of float data type is that “To Store Real Constant Values / Floating Point Values(Numbers with Decimal Places) “
  • Can be negative or postive numbers

Complex:

  • The purpose of Complex Data Type is that “To Store Complex Values”.
  • The General Notation of Complex Values is show bellow.

varname= a + bj

(OR)

varname= a — bj

=>here ‘a’ is called Real Part

=>Here ‘b’ is called Imginary Part

Get Pavan kumar reddy’s stories in your inbox

Join Medium for free to get updates from this writer.

=>The letter ‘j’ represents sqrt(-1)

Sequence Data Types:

  • The purpose of Sequence Data Types is that “To Store or Organize Sequence of Values”.
  • The different types of containers used to store the data are String,List and Tuple

string :

  • The purpose of string data type is that “To store String data or text data or Alphanumeric data or numeric data or special symbols within double Quotes or single quotes or tripple double quotes and tripple single quotes. “
  • Python string belong to str class

Indexing:

The Process of Obtaining a single Value from str object is called Indexing .
=>Index can be either +ve or -ve

Slicing:

The Process of Obtaining Range of Characters / Sub String from Given Main String Data is called Slicing .

List :

  • The purpose of list data type is that “To Store Multiple Values of Same Type or Different Type or Both the types in single object with Unique and Duplicate.
  • The Data in List object Stored / Organized within Square Brackets [ ] and They must be separated by Comma.
  • An object of list maintains Insertion Order.
  • On the object of list, we can perform Both Indexing and Slicing Operations
  • An an object of List belongs to Mutable bcoz Updation done at Same Address.

Tuple:

  • The purpose of tuple data type is that “To store Multiple Values either of Same type or Different Types or Both Types with Unique and Duplicates in single object (Constant Values)”.
  • The elements of tuple must be stored or organized within parentheses ()and Elements separated by comma.
  • An object of tuple maintains Insertion Order
  • An object of tuple belongs to Immutable because tuple’ object does not support item assignment.
  • On the object of tuple, we can perform both Indexing and Slicing Operations.

Set:

  • The purpose of set data type is that “To Store Multiple Values either of Same Type or Different type or Both the Types into single object with Unique Values (Duplicates are not allowed)”.
  • The Elements / Data of set Must be Organized OR Stored within Curly Braces {} and the Values must be separted by comma.
  • Set Elements are Un-ordered
  • On the object of set , we can’t perform Indexing and Slicing Operations becuase set never maintains Insertion Order.
  • An object of set belongs to Both Mutable in the case of adding the elements and Immutable in the case of Item Assignment.

Dictionary:

  • Dictionaries are used to store data values in key:value pairs.
  • A dictionary is a collection which is ordered, changeable and do not allow duplicates.

Mutable and Immutable

Mutable:

  • A Mutable Object is one, whose content can be Changed at SAME ADDRESS.
    Examples: list,set,dict

Immutable:

Immutable Object does not allows to Change Its Content at Same Address( Content Can be Changed and Changed Value placed at NEW Address)
Examples:
int, float,bool,complex,str,

--

--