Python Essentials: Understanding Basic Data Types on Day 10

Archana PrustyArchana Prusty
4 min read

Introduction:

Welcome to Day 10 of my Python journey!

Today, I ventured into the realm of Data Type .

These concepts are essential for efficient data storage.

Data Type :

.Data Type represent the type of data present inside a variable.

. In Python we are not required to specify the type explicitly. Based on value provided,the type will be assigned automatically.Hence Python is Dynamically Typed Language.

Python contains the following inbuilt data types

INT DATA TYPE ~

. int is a predefined class in python.

. to get the manual of int class,

\>>> help ( int )

. how to create the object of int class

obj = int ()

print ( obj, type ( obj ) )

obj = int ( 10 )

print ( obj, type ( obj ) )

obj = int ( "101" , base = 10 )

print ( obj , type ( obj ))

obj = int ( "101" , base = 2 )

print ( obj , type ( obj) )

obj = int ( "101" , base = 8 )

print ( obj , type ( obj ))

obj = int ( "101" , base = 16 )

print ( obj , type ( obj ) )

obj = 10

print ( obj , type ( obj ))

obj = 0b101

print ( obj , type ( obj ) )

obj = 0o101

print ( obj , type ( obj ))

obj = 0x101

print ( obj , type ( obj ))

. python does not support garbage value.

. while working with int class the default value is 0

FLOAT DATA TYPE ~

. float is a predefined class in python

. to get the manual of float class

\>>> help ( float )

. base mechanism is not available for float class.

. in c cpp java to represent float value

. float 1.2f

. double 1.2

. python does not support double data type

. how to create the object of float class

obj = float ()

print ( obj , type ( obj ))

obj = float ( 1.2 )

print ( obj , type ( obj ) )

obj = 11.22

print ( obj , type ( obj ) )

COMPLEX DATA TYPE ~

. complex is a predefined class in python

. to get the manual of complex class

\>>> help ( complex )

. complex object have two different attribute

. real

. imag : represented by j macro

. how to create the object of complex class

obj = complex ()

print ( obj , type ( obj ))

obj = complex ( 10 )

print ( obj , type ( obj ))

obj = complex ( 10, 20 )

print ( obj , type ( obj ))

obj = 10j

print ( obj , type ( obj ))

obj = 1.2 + 2.1j

print ( obj , type ( obj ))

print ( obj . real )

print ( obj . imag )

BOOL TYPE ~

. bool is a predefined class aval in python

. to get the manual of bool class,

\>>> help ( bool )

. python is itself responsible to create the object of bool class

. True and False are the object of bool class created by python / PVM.

objectName = bool ()

. bool class can not be used to create object but we can use to implement type conversion.

\>>> obj =bool()

\>>> type (obj) , obj

(<class 'bool'>, False)

\>>> obj = bool (True)

\>>> type (obj), obj

(<class 'bool'>, True)

\>>> obj = False

\>>> type (obj), obj

(<class 'bool'>, False)

NoneType class / data type ~

. NoneType is a predefined class in python.

. we can not apply help () with NoneType class.

. we can not create the object of NoneType class.

. python is itself responsible to create the object of NoneType class

. the object name created by python of NoneType class is None

\>>> obj = None >>> type (obj),

obj (<class 'NoneType'>, None)

Summery of data type

Challenges:

  1. Understanding data types.

  2. Handling coding errors.

    Resources:

    1. Official Python Documentation: Data types.

    2. W3Schools' Python Tutorial: Data types

    3. Scaler's Python Course: Data Types

Goals for Tomorrow:

  1. Explore something more about data types.

  2. Learn about exceptions.

Conclusion:

Day 10 was a success!

Data types are now under my belt.

What are your views on data types ? Share in the comments below.

Connect with me:

LinkedIn: [ https://www.linkedin.com/in/archana-prusty-4aa0b827a/ ]

GitHub: [ https://github.com/p-archana1 ]

Join the conversation:

Share your own learning experiences or ask questions in the comments.

Next Post:

Day 11: Type conversation

Happy learning!

THANK YOU!!

0
Subscribe to my newsletter

Read articles from Archana Prusty directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Archana Prusty
Archana Prusty

I'm Archana, pursuing Graduation in Information technology and Management. I'm a fresher with expertise in Python programming. I'm excited to apply my skills in AI/ML learning , Python, Java and web development. Looking forward to collaborating and learning from industry experts.