Contact Us

Kockpit is here to help you

Business Form

Arpit Dubey

Basic Data Type In Python

Introduction:

The data type is a data indicator that tells the compiler or interpreter how the programmer intends to use the data and how the values of that type can be maintained.

Python sets the type of data according to the assigned value. Unlike most riggers languages, Python will change the type of variable if the variable value is set to another value.

For example,

Var = 123 # Var is a type of integer
Var = 'hello' # variable `var` is now a type of string

Types of Python Data Types

Python has six common types of data:

  • Numbers

  • Strings

  • Set

  • List

  • Tuples

  • Dictionary
Numbers

Numerical data types store numeric values. They are static data types, meaning that changing the value of the numerical data type results in the newly allocated object.

Numerical objects are created when you give value to them.

For example,

Number1 = 2

Python supports four different types of values -

  • int (signed numbers) - Often referred to as numbers or ints, whole or negative numbers without a decimal point.

  • long (long numbers) - Also called longs, which are whole numbers of infinite size, written as integers followed by a capital letter or lowercase L

  • float (floating prices) - Also called floats, they represent real numbers and the decimal point separates whole numbers and fractions. Floats may also be scientifically labeled, E or e indicating a power of 10 (2.5e2 = 2.5 x 102 = 250)

  • complex numbers (complex numbers) - They are in the form of a + bJ, where a and b are floating and J (or j) represents the square root of -1. The natural part of the number is a, and the imaginary part is b. Complex numbers are not widely used in Python.

Type Format Description
int a = 10 #Signed Integer
long a = 345L (L) #Long numbers, can also be represented octal and hexadecimal
float a = 45.67 (.) #Actual floating point values
complex a = 3.14J (J) #Contains full value in range 0 to 255.
String

A string in Python is a sequence of characters surrounded by either single quotes or double quotes or triple quotes. Only three quoted strings will automatically continue at the end of the line statement. Here, characters are encoded in ASCII characters and manipulated as a combination of 0s and 1s. In this way, the characters are stored in computers as computers only understand the boolean language (0 & 1). The quotes that enclose the characters create a string.

firstName = 'iGala'
lastName = “John”
Set

A set is an unordered collection of data types which is mutable, iterable and contains duplicate elements. The order of elements in a set is undefined regardless of the various elements it may contain.

For Example,

set1 = set([“Geeks”, “For”, “Geeks”])
List

Python comprises lists which are built-in data structures used in storing the sequence of several types of data in Python. The data is represented in square brackets to declare a list followed by the list name.

Lists in Python are ordered and the values in lists are mutable. Thus this factor allows us to change the values anytime and then update them. That is why lists are used so commonly.

A = [] # This is an empty list variable
B = [1, 23, 45, 67] # this list creates the 4-elements list.
C = [2, 4, 'john'] # list may contain different variants.

All lists in Python are [0] based index. When identifying a member of a list or the length of the list, items are always index+1.

Tuple

Tuples are a group of list-like values and are used in similar ways. However, the tuples are fixed in size when given. In Python, the fixed size is considered to be static compared to the list which is in the dynamic range. Tuples are defined in brackets ().

Group = ('Rhino', 'Grasshopper', 'Flamingo', 'Bongo')
Dictionary

A Dictionary in Python is used to store an unordered sequence of data in the form of key-value pair. The data entered in a dictionary is mutable like Lists and is defined into keys & values. The statements are given below highlight the syntax of declaring a dictionary.

Emp = {"emp_name": "Luke", "DOB": "1 January 1969", "Emp_id":99,"Company":"Kockpit Analytics"}
print(type(Emp))
print("printing Employee data .... ")
print(Emp)

Here, the keys are immutable Python objects like integers, strings, or tuples, which must be unique and it contains only a single element. Whereas Values can take form in any kind of Python object (lists, tuples, integers, strings, etc).

room_num = {'john': 425, 'tom': 212}
room_num ['john'] = 645 # set the value associated with the key 'john' to 645
Print (room_num ['tom']) # Print key number 'tom'.
room_num ['isaac'] = 345 # Enter a new key 'isaac' with the corresponding value
print (room_num.keys ()) # print a list of key keys in the dictionary
print ('isaac' in room_num) # test to see if 'isaac' is still in the dictionary. This return is true.

Python Usage in Data Analytics

The dependency on data in the business world has significantly expanded and risen to importance in recent years. Organizations cannot operate further and expand their growth unless they have sufficient and resourceful data to provide insights for them. Since the amount of data is hugely heavy, a very strong command of programming is required to minimize the load and operate files that Excel itself can't handle. The built-in libraries and frameworks of Python are developed on the data types in Python which eases the workflow and creates data structures very easily and quickly.

Kockpit Analytics Pvt. Ltd. is a data analytics business company that provides Big Data and Business Intelligence solutions operating on integrated Python programming systems.

Conclusion:

In this article, we have discussed the fundamental data types in Python and the syntax code for creating them.

Python is the building block of Data Science. Many technologies based on Data Science have emerged that rely on the Python programming language as their core. Moreover, various Python frameworks and libraries are also developing to create new technologies based on Data Science.