Python Data types

Python Data types: Data Type is an attribute that tells which kind of data that a value can have and informs the compilers about predefined attributes required by specific variables or data objects associated. These data types include storage classifications like integers, floating point values, strings, characters, etc.

It has various standard data types that are used to define the operations possible to them and the storage method for each of them.

Python Datatypes

Python has five standard data types. They are as follows:

  • Numbers
  • Strings
  • List
  • Tuple
  • Dictionary

Python Numbers Datatype

Number data type stores numeric values. Number objects will be created when you assign a value to them.

Example

var1 = 1 
var2 = 2

If you want to delete the reference of a number object, you can also do it by using del statement.

Syntax of del: del var1[,var2[,var3[,var4[,….varN]]]] 

You can delete a single object or multiple objects by using del statement.

Example

del var 
del var_a,var_b

Python supports mainly four different numeric types. They are as follows:

  • int (signed integer)
  • float (floating point real values)
  • complex numbers

Python Int Datatype

An int is a data type used to represent real numbers that do not have fractional values. And also Int is called as a signed integer because it stores both positive and negative numbers, known assigned.

Example:

x=1
y=358635874569
z=-326645
print(type(x))
print(type(y))
print (type(z))  

output: 

<class ‘int’ >

<class ‘int’ >

<class ‘int’ >

Python Float Data type

It is a numeric value defined with floating decimal points.

Example:

x=35e3 
y=12E4
z=-86.7e100
print(type(x))
print(type(y))
Print (type(z))

Output:  

<class ‘float’> 

<class ‘float> 

<class ‘float’>

Python Complex Data type

Complex numbers are in the form of  v+iw, where v and w are real numbers, and i represents the unit imaginary numbers equal to the square root of -1.

Example: 

x=3e+26j 
y=6j
z=-6j

Output:

<class ‘complex’>

<class ‘complex’>

<class ‘complex’>

Python Strings

Strings are nothing but a sequence of characters. Python doesn’t support character type, these are treated as strings of length one but considering it as a substring.

Example:

my_string='Hello'
print(my_string)
my_string = "Hello"
print(my_string)my_string = '''Hello'''
print(my_string)my_string = """Hello, welcome tofreshersnow"""
print(my_string)

Output:

Hello

Hello

Hello

Hello  welcome to freshersnow

For learning more about the Strings check here: Python Strings

Python Lists

A list is a collection of ordered and changeable. In python, lists are written in square brackets. To some extent, lists are similar to arrays in C. All the values stored in the list can be accessed by using slice operator ([] and [:]) with indexes starting at 0 at the beginning of the list and going their way to the end -1.

Example:

thislist=[“orange”,“blue“,“green”]
print(thislist)

Output: [‘orange’, ‘blue’ , ‘green’]

For learning more about lists check here: Python Lists

Python Tuple

In Python tuple is a collection which is ordered and unchangeable. It is another sequence data type which is similar to list. A tuple consists of no.of values separated by commas.

Example:

thistuple=("mango","grape","lemon") 
print (thistuple)

Output: (‘mango’, ‘grape’, ‘lemon’)

For more about tuples check here: Python tuples

Python Dictionary

A dictionary maps a set of objects (keys) to another set of objects (values). A Python dictionary is a mapping of unique keys to values. In Python, Dictionaries are mutable, which means they can be changed. And the values that the keys point to can be any Python value.

Example:

thisdict={"brand":"Lamborghini","model":"GT","year": 1963}
print(thisdict)

Output: {‘brand’: ‘Lamborghini’, ‘model’ : ‘GT’, ‘year’ : 1963 }

For learning in detail regarding dictionaries check here: Python Dictionary