Basic Data Types in Python

100+ Python Code Pictures | Download Free Images on Unsplash


Basic Data Types In Python

The data type is the classification which tells compiler/interpreter which type of data is and how much size of memory will occupy by a variable (variable is a memory location which we give some logical name in our programming and the data or information saved on it called its value and it has some physical address also). For example, if declare a variable as int, it will occupy 4 bit in 64 environments. But one thing also we remember in python that If that size still seems a little bit large, remember that a Python int is very different from an int in (for example) c. In Python, an int is a fully-fledged object. This means there's extra overhead. Every Python object contains at least a refcount and a reference to the object's type in addition to other storage; on a 64-bit machine, that takes up 4 bytes! The int internals (as determined by the standard CPython implementation) have also changed over time so that the amount of additional storage taken depends on your version. (Note: Here we discuss the abstract view of all data type later we discuss all datatypes in detail)

  • Numbers:-

  1. Int
  2. Float
  3. Complex Numbers
  • String
  • List
  • Tuple
  • Dictionary
  • Sets
Python Numbers:Integer, floating point number and complex numbers are comes under the python number data type category .In picture below we use inbuild function type to check the data type.



  • Float :- Values with decimal points are the float values, there is no need to specify the data type in Python. It is automatically inferred based on the value we are assigning to a variable. For example here fnum is a float data type




  • Complex Numbers:- Numbers with real and imaginary parts are known as complex numbers. Unlike other programming language such as Java, Python is able to identify these complex numbers with the values. In the following example when we print the type of the variable cnum, it prints as complex number.



  • Strings:-String is a sequence of characters in Python. The data type of String in Python is called “str”.
    Strings in Python are either enclosed with single quotes or double quotes. In the following example we have demonstrated two strings one with the double quotes and other string s2 with the single quotes.



  • List:- The list is an ordered sequence in Python. The list is a collection for different types of data types like float string and an int or we can say that is heterogeneous types.

  • Tuple:- The tuple is also an ordered list in Python. It also likes one-dimensional array but it's heterogeneous. Only the difference between list and tuple is list is a mutable sequence and tuple is an immutable sequence of different data types elements.

Dictionary:-Dictonary is another type of data type in Python. Dictionary is a collection of keys and values where one is key to another its value.


  • Sets:- Sets are other data types in python. Sets are unsequential data elements. Sets are like we use sets in our mathematics. Sets also create by the {} braces difference between dictionary and sets is that there is not key and values pair in it. One important thing is that in sets we can't use indexing because it's unsequential data elements

"Thank You and Never Stop Learning"

Comments

Popular Posts