Data types in Python:

What is python?

Python is a highly versatile and interpreted, high-level dynamic general-purpose programming language. It was created by Guido-van-Rossum in 1989 at CWI in Netherland. In February 1991, van Rossum publish the code. Python emphasizes code readability, easy to use & open source. Python is ranked as the 3rd most leading language followed by JavaScript and Java in a survey held in 2018 by Stack Overflow which give proof to it being the most growing language among others.Since, Python language became popular, and an excellent choice in scripting and rapid application.
Python is currently one of my favorite language to work on because of its code simplicity, powerful enhanced libraries and code readability. Python is the best way to get started in programming language.

Python supports Object Oriented programming approach to develop applications. It is very simple and easy to learn.it also provides lots of high-level data structures.Python is easy to learn yet powerful and versatile scripting language, which makes it attractive for Application Development.Python’s syntax and dynamic typing with its explain nature make it an classic language for scripting and rapid application development.Python supports multiple programming pattern, including object-oriented, imperative, and functional or procedural programming styles.Python is not calculated to work in a particular area, such as web programming. That is why it is known as multipurpose programming language because it can be used with web, enterprise, 3D CAD, etc.Python makes the development and debugging fast because there is no compilation step in Python development and also edit-test-debug cycle is very fast.

Python 2 vs. Python 3

In almost all of the programming languages, when a new version releases, it supports the features and syntax of the existing version of the language, therefore, it is become easier for the projects to switch into the new version. But , in the case of Python, the two versions Python 2 and Python 3 are very much different from each other.
There are some differences between Python 2 and Python 3 are given below:

1) in Python 2 we used print as a statement and used as print “something” to print some string on the console. But in case of , Python 3 we used print as a function and used as print(“something”) to print something on the console.

2)in case of Python 2 we uses the function raw_input() to accept the user’s input. It returns the string representing the value, which is typed by the user. To convert it into the integer value, we need to use the int() function in Python. But in other hand, in Python 3 uses input() function which automatically interpreted the type of input entered by the user. so that, we can cast this value to any type by using primitive functions (int(), str(), etc.).

3)n case of Python 2, the implicit string type is ASCII, whereas, in Python 3, the implicit string type is Unicode.

4)Python 3 is not contain the xrange() function of Python 2. The xrange() is the variant of range() function which returns a xrange object which is works similar to Java iterator. The range() returns some example the function range(0,3) contains 0, 1, 2.

5)There is a small change made in Exception handling in Python 3 that is keyword as which is necessary to be used.

Python data types:

A variable can hold values of different data types. While Python is a dynamic language, we need not to define the data type of the variable while writing the codes or declaring it.In python we can check the data type of the variable by type() function, which returns the type of variable you passed.

Consider the following example to define the values of different data types and checking its types.

Input:

Output:

. Python has the following data types which are buit-in by default.

Numeric data types:

· Integer-This value is represented by int class in python. It can contain positive or negative whole numbers without fraction or decimal numbers in it.

Ex: int (signed integers like 25, 2, 37, etc.)

.Float- This value is represented by float class in python. It is a real number having floating point value. It is specified by a decimal point in it.

Ex: float (floating point numbers like 34.7, 23.8, 4.9 etc.)

Complex Numbers-Complex number is represented by complex class in python. The complex numbers is specified as mixing of real part and imaginary part.

Ex: complex (complex numbers like 4.56j, 7.0 + 6.4j, etc.)

Sequence data types:

· String-A string is a collection of one or more characters in a single quote, double-quote or triple quote. In python there is no character data type, multiple character makes a string. This value is represented by str class.

Ex: str (strings are like ‘java’, ‘python’, ‘c#’ etc.)

. Tuple-Tuple is an ordered collection of Python, it is like a list. The sequence of values stored in a tuple can be of any type like integers, strings and floats, and they are indexed by integers like a list.The element in the tuple are enclosed with a parentheses () and separated with a comma (,). The important difference between list and tuple is that tuples are immutable and lists are mutable.This is represented by tuple class.

Ex: tuple = (1, 2, 3, 4)

. List:Lists are just like the arrays. A single list may contain Data types like Integers, Strings and floats etc. Lists are mutable, so that we can modify the data or value after assigning the value. The elements in a list are indexed with 0 being the first index and 1 is the second index and so on.The items of the tuple are separated with a comma (,) and enclosed in square brackets [ ]. This value is represented by list class.

Ex: list = [1, 2, 3, ‘abc’, 4.5, ‘xyz’]

Dictionary:

Dictionary is a pair of a key&value and the whole called as items.In dictionary the key can hold any primitive data type whereas value can hold an arbitrary Python object.

Dictionary holds key:value pair in this way. Each key-value pair in a Dictionary is separated by a colon (: ) whereas each items separated by a comma ( ,),and enclosed in the curly braces {}. This value is represented by dict class.

Ex: dict = { 1:’c++’, 2:’java’, 3:’python’ }

Boolean:

Boolean is a data type with two built-in values, True or False. This value is represented by the bool class. In Boolean data type True and False with capital ‘T’ and ‘F’ are said to be a valid booleans otherwise python will show an error.

Set:

Set is an unordered collection of data type. It is also like list and it is mutable and has no duplicate elements. The advantage of using a set is, it has an optimized method for checking whether a specific element is contained in the set or not.

It is specified by using the built-in set( ) function. And the data separated by ‘comma’ inside the set. A set contains only unique elements in it, but at the time of set creation multiple duplicate values can be passed.

Ex: set = (a, b, c, d)

Conclusion:

Python is a very good language to learn for a beginner. Hope it will help you to reach your goals in future. Goal may not be an easy one to achieve, but things that are worth doing are often not easy.”

Startup 💼 Assistive Tech ♿️ Visit https://oretes.com/ to learn more