Variables and Objects

👋 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.
Python offers a wide range of operators that help developers write efficient code. This article provides an overview of operators in Python. Arithmetic Operators Arithmetic operators in Python perform mathematical operations. Here are the arithmetic ...
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...

This part of the content will discuss the concepts and principles related to variables and objects in Python. These concepts revolve around how you store, reference, and manipulate data in a Python script.
Python variables just point to various objects. For example, x = 10 means you are essentially defining a pointer named x that points to some other bucket containing the value 10.
# assign 4 to the variable x
x = 10
#You can also assign a value to multiple variables at the same time:
x = y = z = 10
Variable names can point to objects of any type.
It allows objects to change their type during runtime.
x = 10# x is an integer
x = 'Hello World'# now x is a string
x = [10, 20, 30] # now x is a list
Python is an object-oriented programming language in which everything is an object.
x = 10# Integer object
print(type(x)) # <class 'int'>
y = 3.14# Float object
print(type(y)) # <class 'float'>
# Class object
class Person:
pass
print(type(Person)) # <class 'type'>
In Python, literals are the basic building blocks used to represent different types of data. They are fixed values that are directly written into the code and can be assigned to variables.
Numeric Literals
Numeric literals represent numerical values in Python. They can be categorized into three main types: integers, floats, and complex numbers.
# Integer literals
age = 25
# Float literals
pi = 3.14
# Complex number literals
complex_num = 2 + 3j
String literals
String literals represent textual data in Python. They are enclosed in either single quotes (' ') or double quotes (" ").
# String literals
name = "John"
message = 'Hello, World!'
multiline = '''This is a
multiline string.'''
Boolean literals
Boolean literals represent the truth values True and False.
# Boolean literals
is_true = True
is_false = False
None literals
The None literal represents the absence of a value or a null value. It is often used to indicate the absence of a meaningful result or the initialization of variables.
result = None
Containers literals
Python also provides container literals that represent collections of values, such as lists, tuples, sets, and dictionaries.
# List literal
fruits = ['apple', 'banana', 'orange']
# Tuple literal
point = (10, 20)
# Set literal
colors = {'red', 'green', 'blue'}
# Dictionary literal
person = {'name': 'John', 'age': 25}
In conclusion, variables in Python act as named placeholders to store and manipulate data, while objects are the fundamental building blocks that represent data and possess associated behavior and attributes. Literals, on the other hand, are fixed values directly embedded in code, representing specific data types.