Common Data Types

👋 Hi there, I am Nirmal. I am a former software engineer with a keen interest in data science and analytics domains. Besides, I love to contribute to open source and help others to understand various tech stuffs.
Search for a command to run...

👋 Hi there, I am Nirmal. I am a former software engineer with a keen interest in data science and analytics domains. Besides, I love to contribute to open source and help others to understand various tech stuffs.
No comments yet. Be the first to comment.
This series will provides the core concepts of python programming starting from variables, data types, control flow, and functions to some problem solving.
In Python, a string is a sequence of characters that can be manipulated using various functions and methods. Some of the main ways to manipulate strings: Slicing: Extracting a substring from a larger string by specifying a range of indices. Basic syn...
Bias in Machine Learning Bias refers to the simplifying assumptions made by a model to make the target function easier to learn. High bias can lead to underfitting Represents the error introduced by approximating a real-world problem Example: A li...
When it comes to developing software applications, choosing the appropriate architectural style is a critical decision. Among the popular options are microservices and monolithic architecture. By understanding the trade-offs, readers can make well-i...

In a world where information is everywhere, businesses have tons of data at their fingertips. This data is like a goldmine waiting to be used for smart decisions. That's where Big Data analytics and Data Science come in. They're like the experts who ...

Python is a powerful tool for data professionals, largely due to its extensive collection of open-source libraries and packages. In this blog, we'll explore the fundamentals of pandas, with a special focus on its core data structures: Series and Data...

NumPy is a powerful library for numerical computing in Python, offering robust support for large, multi-dimensional arrays and an extensive collection of mathematical functions. Creating Arrays To begin using NumPy, import the library and create arra...

Python has several built-in data types to represent different kinds of data. The main built-in types are:

Finally, note that although Python 2.x had both an int and long type, Python 3 combines the behavior of these two into a single int type.
You can determine the data type of any object using the type() function.
n1 = 4 #Integer literal
n2 = 1j #Complex literal
n3 = 2.32 #float literal
string_literal = "Nirmal" #string literal
true_literal = True #boolean literal
false_literal = False #boolean literal
value = None #None type literal
print(type(n1)) #<class 'int'>
print(type(n2)) #<class 'float'>
print(type(string_literal)) #<class 'str'>
print(type(true_literal)) #<class 'bool'>
print(type(false_literal)) #<class 'bool'>
print(type(value)) #<class 'NoneType'>
Int type
The most basic numerical type is the integer. Any number without a decimal point is an integer.
a, b = 1,2
print(type(a)) # <class 'int'>
print(a+b)# 3
print(a-b)# -1
Float type
The float type in Python represents floating point numbers, which are numbers with decimal points. Floats are implemented as 64-bit double precision values. Python floats have a large range, from around 1e-308 to 1e308.
a = 1.5
b = 2.5
num3 = 1e6 # 1 million
print(type(a))# <class 'float'>
print(a + b) # Output = 4.0
print(a - b) # Output = -1.0
print(a * b)# Output = 3.75
print(a / b)# Output = 0.6
Some math modules to manipulate float :
from math import floor, ceil
floor(1.8) # 1
ceil(1.2) # 2
round(1.75) # 2
Complex type
Complex numbers are numbers with real and imaginary parts.
complex_num = 1 + 2j
print(complex_num.real, complex_num.imag) # Output = 1, 2
#Some operations
a = 1 + 2j
b = 3 + 4j
print(a + b) # (4+6j)
print(a - b)# (-2-2j)
Booleans type
The Boolean type is a simple type with two possible values: True and False, and is returned by comparison operators.
a, b = 4, 5
result = (a < b)
print(result) #True
Booleans can also be constructed using the bool() object constructor.
For example, any numeric type is False if equal to zero, and True otherwise.
print(bool(2012)) #True
print(bool(1)) # True
print(bool(0))# False
Similarly, The Boolean conversion of None is always False and for strings, bool(s) is False for empty strings and True otherwise
print(bool(None)) #False(Always False for None)
print(bool(""))# For empty string it is False
print(bool("Nirmal")) #True
String Type
Strings are sequences of characters, represented using either single or double quotes.
name = "nirmalpandey"#assigning string to variable name
print(name) # output = nirmalpandey
Strings are immutable, meaning once created they cannot be changed, only replaced with a new string.
message = "Bitsnotion"
message[0] = 'b'
print(message) # This will raise a TypeError
None Type
None is returned when a function does not explicitly return a value.
x = None
if x is None:
print("Empty value")
else:
print("Available")
#Output : Empty value