Python Data Types

Python Data Types, What is a Data Type?, Built-in Data Types, Getting the Data Type, Setting the Data Type, and Setting the Specific Data Type.

Data Types in Python

What is a Data Type?

A data type in programming is a classification that specifies which type of value a variable has and what type of mathematical, relational, or logical operations can be applied to it without causing an error.

Example:
Strings, Numbers, and Boolean values, etc.

Variables can store data of different types, and different types can do different things.

x=”India” # A String
y=2.456 # A Floating-Point Value
z=100 # An Integer
a= True # Boolean value (Logical Value)

Note: No explicit declaration of Data types in Python.

Python Built-in Data Types

Python has the following data types built-in by default, in these categories:

Text Type: str
Numeric Types: int, float, complex
Sequence Types: list, tuple, range
Mapping Type: dict
Set Types: set, frozenset
Boolean Type: bool
Binary Types: bytes, bytearray, memoryview

Getting the Data Type

We can get the data type of any object by using the type() function:

a=123
type(a)
It returns int…

b=2.23
type(b)
It returns float…

c=”abcd”
type(c)
It returns str…

Setting the Data Type

In Python, the data type is set when you assign a value to a variable:

Example:

a = “Hello Python” # str
b = 123 # int
c = 12.345 # float
d = 12j # complex
e = [“india”, “china”, “canada”] # list
f = (“selenium”, “uft”, “jmeter”) # tuple
g = {“name” : “Venkat”, “age” : 27} # dict
h = {“java”, “python”, “vbscript”} # set
x = frozenset({“apple”, “banana”, “cherry”}) # frozenset
y = True # bool
etc,

Setting the Specific Data Type

If we want to specify the data type, weu can use the following constructor functions:

Example:

a = str(“India”) # str
b = int(100) # int
c = float(12.5) # float
d = complex(1j) # complex
etc,


Python Syllabus

Python Step by Step Video Tutorial

Python Tutorial

Follow me on social media: