Different Data Types in Python

Photo by Bram Naus on Unsplash

Different Data Types in Python

Python is one of the most popular programming languages. It is a high-level, easy-to-learn interpreted programming language. It was developed by Guido Van Rossum in 1991. Today python is used for many different types of purposes like software development, data analysis, machine learning, robotics, backend web development, desktop application, GUIs, 2d game development, etc. So here in this repository, I am adding Data Structure and Algorithm concepts and problems and their solution.

Data Types in Python

In programming, we need to classify the data or value so that we can perform different operations on different data types for example, The "+" operator will add two values if they are integer or #float while the same operator will concatenate two strings So we can see that the same operator operates different types of values differently based on its data type, hence classifying the values with different data types is very important

Data types available in Python

(i) Integer -> In Python, we represent whole numbers using int (integer). In integers, numbers can lie anywhere from negative infinity to positive infinity which makes it convenient for us to deal with integers without caring much about the memory size it will take because Python will handle it automatically.

 x = 4

 print(type(x))

 output >>  <class "int">

(ii) Float -> In Python to represent a real number having decimal point we use float. It represents both rational and irrational numbers. There can be any number of digits before or after the decimal point.

 x = 4.0

 print(type(x))

 output >>  <class "float">

(iii) Complex Numbers -> In Python, we can also work with complex numbers where we represent imaginary numbers. For example, a + bj is a complex number where a and b are real numbers and j is an imaginary number.

  x = 2 + 3j

  print(type(x))

  output >> <class "complex">

(iv) String -> String values are the combination of letters, characters, numbers, and special characters inside the single, double, or even triple quotation mark. Most of the time we use single and double quotation marks for single-line strings and while we want to write multi-line strings we use triple quotation marks.

  x = "Hello World"

  print(type(x))

  output >> <class 'str'>

(v) Boolean -> Boolean has only two values True (T is always capital) and False (F is always capital). We use boolean data type when we have to make decisions or write conditional statements. We can also represent boolean values by using numbers such as 1 for True and 0 for False.

  x = True

  print(type(x))

  output >> <class 'bool'>

(vi) None -> Suppose a situation where you have to declare a variable without initializing that variable then there comes no type to save you. It is used to declare a variable with any initial value.

  x = None

  print(type(x))

  output >> <class 'NoneType'>

Summary These are the data types available in python and we will discuss them in details in my next post

Thanks For Reading