<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Bits Notion]]></title><description><![CDATA[Bits Notion]]></description><link>https://bitsnotion.com</link><image><url>https://cdn.hashnode.com/res/hashnode/image/upload/v1719816081076/458d4b0b-6158-4b42-ab6c-0c80bfbdea9a.png</url><title>Bits Notion</title><link>https://bitsnotion.com</link></image><generator>RSS for Node</generator><lastBuildDate>Fri, 10 Apr 2026 11:32:42 GMT</lastBuildDate><atom:link href="https://bitsnotion.com/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Bias, Variance, Under-fitting, and Over-fitting and bias variance tradeoff]]></title><description><![CDATA[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...]]></description><link>https://bitsnotion.com/bias-variance-under-fitting-and-over-fitting-and-bias-variance-tradeoff</link><guid isPermaLink="true">https://bitsnotion.com/bias-variance-under-fitting-and-over-fitting-and-bias-variance-tradeoff</guid><dc:creator><![CDATA[Nirmal Pandey]]></dc:creator><pubDate>Wed, 14 Jan 2026 01:25:13 GMT</pubDate><content:encoded><![CDATA[<h2 id="heading-bias-in-machine-learning"><strong>Bias in Machine Learning</strong></h2>
<p>Bias refers to the simplifying assumptions made by a model to make the target function easier to learn.</p>
<ul>
<li><p>High bias can lead to underfitting</p>
</li>
<li><p>Represents the error introduced by approximating a real-world problem</p>
</li>
<li><p>Example: A linear regression model trying to fit a non-linear relationship</p>
</li>
<li><p>For example: A facial recognition system trained primarily on one ethnic group may show high bias when attempting to identify individuals from other ethnicities.</p>
</li>
</ul>
<h2 id="heading-variance-in-machine-learning"><strong>Variance in Machine Learning</strong></h2>
<p>Variance is the amount that the estimate of the target function will change if different training data is used.</p>
<ul>
<li><p>High variance can lead to overfitting</p>
</li>
<li><p>Indicates how sensitive the model is to fluctuations in the training data</p>
</li>
<li><p>Example: A decision tree with many branches, fitting noise in the training data</p>
</li>
<li><p>For example: A stock price prediction model that performs exceptionally well on historical data but fails to accurately forecast future prices due to overemphasis on past patterns.</p>
</li>
</ul>
<h2 id="heading-the-underfitting-problem"><strong>The Underfitting Problem</strong></h2>
<p>Underfitting occurs when a model is too simple to capture the underlying patterns in the data.</p>
<ul>
<li><p>Results in poor performance on both training and testing data</p>
</li>
<li><p>Signs include consistently poor performance and high errors</p>
</li>
<li><p>Often due to oversimplified models or insufficient feature engineering</p>
</li>
<li><p>For example: A linear model trying to predict housing prices based solely on square footage, ignoring crucial factors like location and amenities.</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1740697337779/2287c204-aca8-46ca-8eb3-e722674ed52b.png" alt class="image--center mx-auto" /></p>
</li>
</ul>
<h2 id="heading-the-overfitting-challenge"><strong>The Overfitting Challenge</strong></h2>
<p>Overfitting happens when a model learns the training data too well, including its noise and fluctuations, but fails with testing or unseen data.</p>
<ul>
<li><p>Performs well on training data but poorly on new, unseen data</p>
</li>
<li><p>Characterized by high variance and complex decision boundaries</p>
</li>
<li><p>Can occur due to excessive model complexity or training on limited data</p>
</li>
<li><p>For world example: An image classification model that correctly identifies dogs in training images by memorizing specific background details (like grass) rather than learning general dog features.</p>
</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1740697384854/4c3c1f71-929f-437e-91d5-760d6748f3ff.png" alt class="image--center mx-auto" /></p>
<h2 id="heading-balancing-act-the-bias-variance-tradeoff"><strong>Balancing Act: The Bias-Variance Tradeoff</strong></h2>
<p>The bias-variance tradeoff involves finding the optimal balance between underfitting and overfitting.</p>
<ul>
<li><p>Increasing model complexity generally decreases bias but increases variance</p>
</li>
<li><p>The goal is to find the sweet spot with low bias and low variance</p>
</li>
<li><p>Techniques like cross-validation and regularization help achieve this balance</p>
</li>
<li><p>Real-world example: In predicting student academic performance, finding the right set of features (e.g., past grades, study habits) without including irrelevant factors (e.g., favorite color) to create a model that generalizes well.</p>
</li>
</ul>
<p><img src="https://assets.leetcode.com/uploads/2019/02/11/model_complexity_bias_variance.png" alt class="image--center mx-auto" /></p>
<p>By understanding and managing the bias-variance tradeoff, data scientists can develop more robust and accurate machine learning models that perform well on both training and unseen data</p>
]]></content:encoded></item><item><title><![CDATA[Monolithic vs Microservices architecture]]></title><description><![CDATA[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...]]></description><link>https://bitsnotion.com/monolithic-vs-microservices-architecture</link><guid isPermaLink="true">https://bitsnotion.com/monolithic-vs-microservices-architecture</guid><category><![CDATA[monolithic architecture]]></category><category><![CDATA[microservice]]></category><dc:creator><![CDATA[Nirmal Pandey]]></dc:creator><pubDate>Thu, 08 Jan 2026 18:15:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1687870504509/af1eb46e-7c37-4ac9-bb16-1347f40d8561.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<ul>
<li><p>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.</p>
</li>
<li><p>By understanding the trade-offs, readers can make well-informed decisions that align with their project requirements.</p>
</li>
</ul>
<h3 id="heading-monolithic-architecture"><strong>Monolithic Architecture</strong></h3>
<p>Monolithic architecture represents the traditional approach where an application is developed as a single, self-contained unit. In this model, all components, including the user interface, business logic, and database access, are tightly integrated and deployed together.</p>
<p><img src="https://dz2cdn1.dzone.com/storage/temp/11234811-monolithic-example.png" alt="Example: An eCommerce App built using Microservices Architecture" /></p>
<p><strong>Advantages:</strong></p>
<ul>
<li><p>Simplicity: Monolithic architectures are generally easier to develop, test, and deploy since all components reside within a single codebase.</p>
</li>
<li><p>Performance: Inter-component communication in monolithic applications is efficient as it avoids the overhead associated with network calls.</p>
</li>
<li><p>Ease of Debugging: Debugging and troubleshooting are simplified since all components run within the same process.</p>
</li>
</ul>
<p><strong>Challenges:</strong></p>
<ul>
<li><p>Scalability: Scaling monolithic applications can be challenging as the entire application needs to be replicated, even if only specific components require additional resources.</p>
</li>
<li><p>Limited Technology Choices: Monolithic architectures may restrict the use of different technologies or frameworks since the entire application must adhere to the same technology stack.</p>
</li>
<li><p>Maintainability: As monolithic applications grow larger, maintaining and modifying them becomes more difficult due to their tightly coupled nature.</p>
</li>
</ul>
<h3 id="heading-microservices-architecture">Microservices Architecture</h3>
<p>Microservices architecture involves breaking down an application into small, loosely coupled services that can be independently developed, deployed, and scaled. Each service is responsible for a specific business capability and communicates with other services through lightweight protocols.</p>
<p><img src="https://dz2cdn1.dzone.com/storage/temp/11234813-microservices-example.png" alt="Example: An eCommerce App built using Monolithic Architecture" /></p>
<p><strong>Advantages</strong></p>
<ul>
<li><p>Simplifies application complexity by breaking it down into manageable services, leading to faster development and easier maintenance.</p>
</li>
<li><p>Enables independent development of each service by dedicated teams, promoting agility and specialization.</p>
</li>
<li><p>Facilitates the adoption of new technologies as developers have the freedom to choose the most suitable tools for their services.</p>
</li>
<li><p>Supports independent deployment of services, enabling continuous deployment in complex applications.</p>
</li>
<li><p>Allows for individual scaling of services, optimizing resource utilization.</p>
</li>
</ul>
<p><strong>Drawbacks</strong></p>
<ul>
<li><p>Introduces complexity due to the distributed nature of microservices, requiring additional considerations for inter-service communication and handling partial failures.</p>
</li>
<li><p>Imposes challenges for managing business transactions that involve multiple databases owned by different services, often necessitating eventual consistency approaches.</p>
</li>
<li><p>Increases testing complexity as each service and its dependencies must be configured and launched for testing.</p>
</li>
<li><p>Makes changes spanning multiple services more difficult to implement, requiring careful planning and coordination.</p>
</li>
<li><p>Adds complexity to deployment with a larger number of services and instances, necessitating automation and service discovery mechanisms.</p>
</li>
</ul>
<p>It's important to weigh these advantages and drawbacks when considering the adoption of a microservices architecture for your project.</p>
<h3 id="heading-choosing-the-right-approach">Choosing the Right Approach:</h3>
<p>Choosing between microservices and monolithic architecture depends on several factors, including project size, complexity, scalability requirements, and team capabilities.</p>
<ul>
<li><p>Monolithic Architecture is suitable when:</p>
<ul>
<li><p>The application is relatively small and straightforward.</p>
</li>
<li><p>Simplicity and faster development are of paramount importance.</p>
</li>
<li><p>Scalability requirements are low to moderate.</p>
</li>
<li><p>The team has limited experience with distributed systems.</p>
</li>
</ul>
</li>
<li><p>Microservices Architecture is suitable when:</p>
<ul>
<li><p>The application is large and complex, with multiple interdependent components.</p>
</li>
<li><p>Scalability requirements are high, necessitating independent scaling of services.</p>
</li>
<li><p>The team possesses experience in building and managing distributed systems.</p>
</li>
<li><p>There is a need for technological flexibility, allowing the use of different languages or frameworks.</p>
</li>
</ul>
</li>
</ul>
]]></content:encoded></item><item><title><![CDATA[Big Data analytics and Data science]]></title><description><![CDATA[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 ...]]></description><link>https://bitsnotion.com/big-data-analytics-and-data-science</link><guid isPermaLink="true">https://bitsnotion.com/big-data-analytics-and-data-science</guid><category><![CDATA[Data Science]]></category><category><![CDATA[data analysis]]></category><category><![CDATA[big data]]></category><dc:creator><![CDATA[Nirmal Pandey]]></dc:creator><pubDate>Wed, 12 Nov 2025 19:15:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1694597606046/6a4f86f7-1e60-4dd6-b046-53a76a0ee871.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>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 turn this data into valuable insights. In this article, we'll explore what these fields do and how they work together.</p>
<h2 id="heading-big-data-analytics">Big Data Analytics</h2>
<p>Big Data analytics is the process of extracting meaningful insights from vast and complex data sets. It revolves around the utilization of specialized tools and techniques to analyze, process, and interpret data to facilitate informed decision-making.</p>
<h3 id="heading-key-components-of-big-data-analytics">Key Components of Big Data Analytics</h3>
<ol>
<li><p><strong>Data Collection and Ingestion</strong>: Gathering data from diverse sources, including social media, IoT devices, sensors, and more. This step involves data cleaning and transformation for standardized analysis.</p>
</li>
<li><p><strong>Storage and Management</strong>: Employing distributed storage systems and cloud technologies to store and manage large volumes of data efficiently.</p>
</li>
<li><p><strong>Processing and Analysis</strong>: Utilizing parallel processing frameworks like Hadoop and Spark for efficient handling of massive data sets.</p>
</li>
<li><p><strong>Visualization and Reporting</strong>: Transforming complex data into visually comprehensible formats through charts, graphs, and dashboards.</p>
</li>
<li><p><strong>Machine Learning Integration</strong>: Applying advanced algorithms to uncover patterns, predict trends, and automate decision-making processes.</p>
</li>
</ol>
<h2 id="heading-data-science">Data Science</h2>
<p>Data Science is a multidisciplinary field that combines elements of statistics, mathematics, programming, and domain expertise. It revolves around extracting knowledge and insights from data to drive informed business decisions.</p>
<h3 id="heading-key-components-of-data-science">Key Components of Data Science</h3>
<ol>
<li><p><strong>Statistical Analysis and Modeling</strong>: Employing statistical techniques to uncover patterns, correlations, and trends within data sets.</p>
</li>
<li><p><strong>Machine Learning and Predictive Modeling</strong>: Building and deploying algorithms to make predictions or classifications based on historical data.</p>
</li>
<li><p><strong>Data Mining</strong>: Exploring large datasets to discover hidden patterns or relationships.</p>
</li>
<li><p><strong>Data Cleaning and Preparation</strong>: Ensuring data quality and compatibility for analysis through processes like normalization and transformation.</p>
</li>
<li><p><strong>Domain Knowledge Integration</strong>: Combining expertise in a specific field with data analysis to derive actionable insights.</p>
</li>
</ol>
<h2 id="heading-big-data-analytics-meets-data-science">Big Data Analytics Meets Data Science</h2>
<p>While Big Data analytics focuses on handling and processing large volumes of data, Data Science brings the analytical and predictive capabilities that unlock the true potential of this information. Together, they form a powerhouse that drives innovation, efficiency, and competitiveness across industries.</p>
<h3 id="heading-realizing-the-potential">Realizing the Potential</h3>
<ol>
<li><p><strong>Personalized Marketing</strong>: By combining Big Data analytics for segmentation with Data Science for predictive modeling, businesses can deliver highly targeted and effective marketing campaigns.</p>
</li>
<li><p><strong>Healthcare Advancements</strong>: The fusion of Big Data analytics and Data Science has revolutionized patient care through personalized treatment plans, predictive diagnostics, and drug discovery.</p>
</li>
<li><p><strong>Predictive Maintenance</strong>: Industries leverage this duo to forecast when machinery and equipment might fail, enabling proactive maintenance and reducing downtime.</p>
</li>
</ol>
<h3 id="heading-ethical-considerations-and-data-privacy">Ethical Considerations and Data Privacy</h3>
<p>As these fields continue to evolve, it's crucial to address ethical concerns surrounding data usage. Striking a balance between innovation and privacy is paramount to ensuring the responsible application of Big Data analytics and Data Science.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>Big Data analytics and Data Science stand at the forefront of the data-driven revolution, offering organizations unparalleled opportunities for growth and innovation. By harnessing their combined power, businesses can unlock a new era of informed decision-making, predictive insights, and strategic advantage in an increasingly competitive landscape. The synergy between these fields will continue to shape industries, redefine processes, and drive the next wave of technological advancements.</p>
]]></content:encoded></item><item><title><![CDATA[Mastering the Fundamentals of Pandas]]></title><description><![CDATA[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...]]></description><link>https://bitsnotion.com/mastering-the-fundamentals-of-pandas</link><guid isPermaLink="true">https://bitsnotion.com/mastering-the-fundamentals-of-pandas</guid><category><![CDATA[Python 3]]></category><category><![CDATA[pandas]]></category><category><![CDATA[panda dataframe]]></category><category><![CDATA[dataset]]></category><dc:creator><![CDATA[Nirmal Pandey]]></dc:creator><pubDate>Mon, 22 Apr 2024 18:15:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1717947820710/bc6f280c-809a-4dd6-8927-ce39a1a17a1d.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>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 DataFrame.</p>
<h2 id="heading-the-building-blocks-series-and-dataframe">The Building Blocks: Series and DataFrame</h2>
<h3 id="heading-series-the-one-dimensional-powerhouse">Series: The One-Dimensional Powerhouse</h3>
<p>A Series in pandas is akin to a column in a spreadsheet or a one-dimensional NumPy array. It’s a labeled array that can hold any data type, with each element having an associated label called an index. This indexing feature allows for efficient and intuitive data manipulation.</p>
<p><strong>Here’s a quick look at how to create and use a Series:</strong></p>
<pre><code class="lang-python"><span class="hljs-keyword">import</span> pandas <span class="hljs-keyword">as</span> pd
<span class="hljs-comment"># Creating a Series</span>
s = pd.Series([<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>])
print(s)
</code></pre>
<p><strong>Output:</strong></p>
<pre><code class="lang-python"><span class="hljs-number">0</span>    <span class="hljs-number">1</span>
<span class="hljs-number">1</span>    <span class="hljs-number">2</span>
<span class="hljs-number">2</span>    <span class="hljs-number">3</span>
<span class="hljs-number">3</span>    <span class="hljs-number">4</span>
<span class="hljs-number">4</span>    <span class="hljs-number">5</span>
dtype: int64
</code></pre>
<h3 id="heading-dataframe-the-two-dimensional-workhorse">DataFrame : The Two-Dimensional Workhorse</h3>
<p>A DataFrame is the heart of pandas, representing a two-dimensional labeled data structure with columns and rows, similar to a table or spreadsheet. Each column in a DataFrame is a Series.</p>
<p><strong>Here’s how to create a DataFrame:</strong></p>
<pre><code class="lang-python"><span class="hljs-comment"># Creating a DataFrame from a dictionary</span>
data = {<span class="hljs-string">'col1'</span>: [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>], <span class="hljs-string">'col2'</span>: [<span class="hljs-number">3</span>, <span class="hljs-number">4</span>]}
df = pd.DataFrame(data)
print(df)
</code></pre>
<p><strong>Output:</strong></p>
<pre><code class="lang-python">   col1  col2
<span class="hljs-number">0</span>     <span class="hljs-number">1</span>     <span class="hljs-number">3</span>
<span class="hljs-number">1</span>     <span class="hljs-number">2</span>     <span class="hljs-number">4</span>
</code></pre>
<pre><code class="lang-python"><span class="hljs-comment"># Creating a DataFrame from a NumPy array</span>
<span class="hljs-keyword">import</span> numpy <span class="hljs-keyword">as</span> np
df2 = pd.DataFrame(np.array([[<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>], [<span class="hljs-number">4</span>, <span class="hljs-number">5</span>, <span class="hljs-number">6</span>], [<span class="hljs-number">7</span>, <span class="hljs-number">8</span>, <span class="hljs-number">9</span>]]), columns=[<span class="hljs-string">'a'</span>, <span class="hljs-string">'b'</span>, <span class="hljs-string">'c'</span>])
print(df2)
</code></pre>
<p><strong>Output:</strong></p>
<pre><code class="lang-python">   a  b  c
<span class="hljs-number">0</span>  <span class="hljs-number">1</span>  <span class="hljs-number">2</span>  <span class="hljs-number">3</span>
<span class="hljs-number">1</span>  <span class="hljs-number">4</span>  <span class="hljs-number">5</span>  <span class="hljs-number">6</span>
<span class="hljs-number">2</span>  <span class="hljs-number">7</span>  <span class="hljs-number">8</span>  <span class="hljs-number">9</span>
</code></pre>
<h2 id="heading-unlocking-the-potential-of-dataframe-attributes-and-methods">Unlocking the Potential of DataFrame Attributes and Methods</h2>
<p>DataFrames come with a plethora of built-in attributes and methods that simplify common data analysis tasks. Here are some of the most commonly used ones:</p>
<h3 id="heading-essential-attributes">Essential Attributes</h3>
<ul>
<li><p><code>columns</code>: Returns the column labels of the DataFrame.</p>
</li>
<li><p><code>dtypes</code>: Returns the data types of the columns.</p>
</li>
<li><p><code>iloc</code>: Accesses rows and columns using integer-based indexing.</p>
</li>
<li><p><code>loc</code>: Accesses rows and columns by labels or Boolean arrays.</p>
</li>
<li><p><code>shape</code>: Returns a tuple representing the dimensionality.</p>
</li>
<li><p><code>values</code>: Returns a NumPy representation of the DataFrame.</p>
</li>
</ul>
<p><strong>Examples:</strong></p>
<pre><code class="lang-python">print(df2.columns)
print(df2.dtypes)
print(df2.shape)
print(df2.values)
</code></pre>
<p><strong>Output:</strong></p>
<pre><code class="lang-python">Index([<span class="hljs-string">'a'</span>, <span class="hljs-string">'b'</span>, <span class="hljs-string">'c'</span>], dtype=<span class="hljs-string">'object'</span>)

a    int64
b    int64
c    int64
dtype: object

(<span class="hljs-number">3</span>, <span class="hljs-number">3</span>)

array([[<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>],
       [<span class="hljs-number">4</span>, <span class="hljs-number">5</span>, <span class="hljs-number">6</span>],
       [<span class="hljs-number">7</span>, <span class="hljs-number">8</span>, <span class="hljs-number">9</span>]])
</code></pre>
<h3 id="heading-vital-methods">Vital Methods</h3>
<ul>
<li><p><code>apply()</code>: Applies a function along an axis.</p>
</li>
<li><p><code>copy()</code>: Creates a copy of the DataFrame.</p>
</li>
<li><p><code>describe()</code>: Provides descriptive statistics.</p>
</li>
<li><p><code>drop()</code>: Drops specified labels from rows or columns.</p>
</li>
<li><p><code>groupby()</code>: Groups DataFrame using a mapper or by a Series of columns.</p>
</li>
<li><p><code>head()</code>: Returns the first n rows.</p>
</li>
<li><p><code>info()</code>: Prints a concise summary of the DataFrame.</p>
</li>
<li><p><code>isna()</code>: Detects missing values.</p>
</li>
<li><p><code>sort_values()</code>: Sorts by the values along an axis.</p>
</li>
<li><p><code>value_counts()</code>: Returns a Series containing counts of unique values.</p>
</li>
</ul>
<p>Example:</p>
<pre><code class="lang-python">print(df2.describe())
</code></pre>
<p>Output:</p>
<pre><code class="lang-python">              a         b         c
count  <span class="hljs-number">3.000000</span>  <span class="hljs-number">3.000000</span>  <span class="hljs-number">3.000000</span>
mean   <span class="hljs-number">4.000000</span>  <span class="hljs-number">5.000000</span>  <span class="hljs-number">6.000000</span>
std    <span class="hljs-number">3.000000</span>  <span class="hljs-number">3.000000</span>  <span class="hljs-number">3.000000</span>
min    <span class="hljs-number">1.000000</span>  <span class="hljs-number">2.000000</span>  <span class="hljs-number">3.000000</span>
<span class="hljs-number">25</span>%    <span class="hljs-number">2.500000</span>  <span class="hljs-number">3.500000</span>  <span class="hljs-number">4.500000</span>
<span class="hljs-number">50</span>%    <span class="hljs-number">4.000000</span>  <span class="hljs-number">5.000000</span>  <span class="hljs-number">6.000000</span>
<span class="hljs-number">75</span>%    <span class="hljs-number">5.500000</span>  <span class="hljs-number">6.500000</span>  <span class="hljs-number">7.500000</span>
max    <span class="hljs-number">7.000000</span>  <span class="hljs-number">8.000000</span>  <span class="hljs-number">9.000000</span>
</code></pre>
<h2 id="heading-selecting-data-with-pandas">Selecting Data with Pandas</h2>
<p>Selecting and manipulating data within a DataFrame is a crucial skill. Pandas offers several ways to achieve this.</p>
<h3 id="heading-row-selection">Row Selection</h3>
<h4 id="heading-using-loc">Using <code>loc[]</code>:</h4>
<p>Select rows by label:</p>
<pre><code class="lang-python">df = pd.DataFrame({
   <span class="hljs-string">'A'</span>: [<span class="hljs-string">'alpha'</span>, <span class="hljs-string">'apple'</span>, <span class="hljs-string">'arsenic'</span>, <span class="hljs-string">'angel'</span>, <span class="hljs-string">'android'</span>],
   <span class="hljs-string">'B'</span>: [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>],
   <span class="hljs-string">'C'</span>: [<span class="hljs-string">'coconut'</span>, <span class="hljs-string">'curse'</span>, <span class="hljs-string">'cassava'</span>, <span class="hljs-string">'cuckoo'</span>, <span class="hljs-string">'clarinet'</span>],
   <span class="hljs-string">'D'</span>: [<span class="hljs-number">6</span>, <span class="hljs-number">7</span>, <span class="hljs-number">8</span>, <span class="hljs-number">9</span>, <span class="hljs-number">10</span>]
}, index=[<span class="hljs-number">0</span>, <span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>])

print(df.loc[<span class="hljs-number">1</span>])
print(df.loc[[<span class="hljs-number">1</span>, <span class="hljs-number">3</span>]])
</code></pre>
<p><strong>Output:</strong></p>
<pre><code class="lang-python">A       apple
B           <span class="hljs-number">2</span>
C       curse
D           <span class="hljs-number">7</span>
Name: <span class="hljs-number">1</span>, dtype: object

          A  B       C  D
<span class="hljs-number">1</span>     apple  <span class="hljs-number">2</span>   curse  <span class="hljs-number">7</span>
<span class="hljs-number">3</span>     angel  <span class="hljs-number">4</span>  cuckoo  <span class="hljs-number">9</span>
</code></pre>
<h4 id="heading-using-iloc">Using <code>iloc[]</code>:</h4>
<p>Select rows by position:</p>
<pre><code class="lang-python">print(df.iloc[<span class="hljs-number">1</span>])
print(df.iloc[[<span class="hljs-number">0</span>, <span class="hljs-number">2</span>]])
</code></pre>
<p><strong>Output:</strong></p>
<pre><code class="lang-python">A       apple
B           <span class="hljs-number">2</span>
C       curse
D           <span class="hljs-number">7</span>
Name: <span class="hljs-number">1</span>, dtype: object

         A  B        C  D
<span class="hljs-number">0</span>     alpha  <span class="hljs-number">1</span>  coconut  <span class="hljs-number">6</span>
<span class="hljs-number">2</span>   arsenic  <span class="hljs-number">3</span>   cassava  <span class="hljs-number">8</span>
</code></pre>
<h3 id="heading-column-selection">Column Selection</h3>
<h4 id="heading-bracket-notation">Bracket Notation:</h4>
<pre><code class="lang-python">print(df[<span class="hljs-string">'C'</span>])
print(df[[<span class="hljs-string">'A'</span>, <span class="hljs-string">'C'</span>]])
</code></pre>
<p><strong>Output:</strong></p>
<pre><code class="lang-python"><span class="hljs-number">0</span>    coconut
<span class="hljs-number">1</span>      curse
<span class="hljs-number">2</span>    cassava
<span class="hljs-number">3</span>     cuckoo
<span class="hljs-number">4</span>   clarinet
Name: C, dtype: object

        A        C
<span class="hljs-number">0</span>   alpha  coconut
<span class="hljs-number">1</span>   apple    curse
<span class="hljs-number">2</span> arsenic  cassava
<span class="hljs-number">3</span>   angel   cuckoo
<span class="hljs-number">4</span> android clarinet
</code></pre>
<h4 id="heading-dot-notation">Dot Notation:</h4>
<pre><code class="lang-python">print(df.A)
</code></pre>
<p><strong>Output:</strong></p>
<pre><code class="lang-python"><span class="hljs-number">0</span>     alpha
<span class="hljs-number">1</span>     apple
<span class="hljs-number">2</span>   arsenic
<span class="hljs-number">3</span>     angel
<span class="hljs-number">4</span>   android
Name: A, dtype: object
</code></pre>
<h3 id="heading-selecting-rows-and-columns-together">Selecting Rows and Columns Together</h3>
<h4 id="heading-using-loc-1">Using <code>loc[]</code>:</h4>
<pre><code class="lang-python">print(df.loc[<span class="hljs-number">0</span>:<span class="hljs-number">2</span>, [<span class="hljs-string">'A'</span>, <span class="hljs-string">'C'</span>]])
</code></pre>
<p>Output:</p>
<pre><code class="lang-python">        A        C
<span class="hljs-number">0</span>   alpha  coconut
<span class="hljs-number">1</span>   apple    curse
<span class="hljs-number">2</span> arsenic  cassava
</code></pre>
<h4 id="heading-using-iloc-1">Using <code>iloc[]</code>:</h4>
<pre><code class="lang-python">print(df.iloc[[<span class="hljs-number">2</span>, <span class="hljs-number">4</span>], <span class="hljs-number">0</span>:<span class="hljs-number">3</span>])
</code></pre>
<p><strong>Output:</strong></p>
<pre><code class="lang-python">        A  B        C
<span class="hljs-number">2</span> arsenic  <span class="hljs-number">3</span>   cassava
<span class="hljs-number">4</span> android  <span class="hljs-number">5</span>  clarinet
</code></pre>
<h2 id="heading-key-takeaways">Key Takeaways</h2>
<p>Pandas DataFrames are an essential tool for working with tabular data. Each row and column in a DataFrame is represented by a pandas Series, making data manipulation intuitive and efficient. The robust suite of methods and attributes available in pandas allows for sophisticated data operations with minimal code. As you gain experience with pandas, you’ll find it an invaluable tool in your data science toolkit.</p>
<h2 id="heading-additional-resources">Additional Resources</h2>
<p>For more detailed information, refer to the official pandas documentation:</p>
<ul>
<li><p><a target="_blank" href="https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.html">pandas DataFrame documentation</a></p>
</li>
<li><p><a target="_blank" href="https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.html">pandas Series documentation</a></p>
</li>
<li><p><a target="_blank" href="https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html">pandas selection documentation</a></p>
</li>
</ul>
<p>By mastering the fundamentals of pandas, you'll be on your way to becoming a proficient and effective data professional.</p>
<hr />
]]></content:encoded></item><item><title><![CDATA[Mastering NumPy Arrays]]></title><description><![CDATA[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...]]></description><link>https://bitsnotion.com/mastering-numpy-arrays</link><guid isPermaLink="true">https://bitsnotion.com/mastering-numpy-arrays</guid><category><![CDATA[numpy]]></category><category><![CDATA[array]]></category><category><![CDATA[array methods]]></category><category><![CDATA[Python 3]]></category><category><![CDATA[Python]]></category><dc:creator><![CDATA[Nirmal Pandey]]></dc:creator><pubDate>Tue, 09 Apr 2024 18:15:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1717673411772/4103a919-3cf4-410f-9f29-720edbf97098.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>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.</p>
<h2 id="heading-creating-arrays">Creating Arrays</h2>
<p>To begin using NumPy, import the library and create arrays:</p>
<pre><code class="lang-python"><span class="hljs-keyword">import</span> numpy <span class="hljs-keyword">as</span> np

<span class="hljs-comment"># 1D array (Similar to a list.)</span>
array_1d = np.array([<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>])
print(array_1d)  <span class="hljs-comment"># Output: [1 2 3]</span>

<span class="hljs-comment"># 2D array(Similar to a table.)</span>
array_2d = np.array([(<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>), (<span class="hljs-number">4</span>, <span class="hljs-number">5</span>, <span class="hljs-number">6</span>)])
print(array_2d)  <span class="hljs-comment"># Output: [[1 2 3] [4 5 6]]</span>

<span class="hljs-comment"># 3D array(Similar to two tables)</span>
array_3d = np.array([[[<span class="hljs-number">1</span>, <span class="hljs-number">2</span>], [<span class="hljs-number">3</span>, <span class="hljs-number">4</span>]], [[<span class="hljs-number">5</span>, <span class="hljs-number">6</span>], [<span class="hljs-number">7</span>, <span class="hljs-number">8</span>]]])
print(array_3d)  <span class="hljs-comment"># Output: [[[1 2] [3 4]] [[5 6] [7 8]]]</span>
</code></pre>
<h2 id="heading-special-arrays">Special Arrays</h2>
<p>Create arrays filled with <code>zeros()</code>, <code>ones()</code>, <code>full()</code>.</p>
<pre><code class="lang-python"><span class="hljs-comment"># Array of zeros</span>
print(np.zeros((<span class="hljs-number">3</span>, <span class="hljs-number">2</span>)))  <span class="hljs-comment"># Output: [[0 0] [0 0] [0 0]]</span>

<span class="hljs-comment"># Array of ones</span>
print(np.ones((<span class="hljs-number">2</span>, <span class="hljs-number">2</span>)))  <span class="hljs-comment"># Output: [[1 1] [1 1]]</span>

<span class="hljs-comment"># Array filled with a specific value</span>
print(np.full((<span class="hljs-number">5</span>, <span class="hljs-number">3</span>), <span class="hljs-number">8</span>))  <span class="hljs-comment"># Output: [[8 8 8] [8 8 8] [8 8 8] [8 8 8] [8 8 8]]</span>
</code></pre>
<h2 id="heading-array-attributes">Array attributes</h2>
<p>NumPy arrays have several attributes that enable you to access information about the array. Some of the most commonly used attributes include the following:</p>
<ul>
<li><p><a target="_blank" href="https://numpy.org/doc/stable/reference/generated/numpy.ndarray.shape.html">ndarray.shape:</a> returns a tuple of the array’s dimensions.</p>
</li>
<li><p><a target="_blank" href="https://numpy.org/doc/stable/reference/generated/numpy.ndarray.dtype.html">ndarray.dtype:</a> returns the data type of the array’s contents.</p>
</li>
<li><p><a target="_blank" href="https://numpy.org/doc/stable/reference/generated/numpy.ndarray.size.html">ndarray.size:</a> returns the total number of elements in the array.</p>
</li>
<li><p><a target="_blank" href="https://numpy.org/doc/stable/reference/generated/numpy.ndarray.T.html">ndarray.T</a>: returns the array transposed rows becomes columns, columns become rows).</p>
</li>
<li><pre><code class="lang-python">      array = np.array([(<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>), (<span class="hljs-number">4</span>, <span class="hljs-number">5</span>, <span class="hljs-number">6</span>)])
      print(array )<span class="hljs-comment"># Output:  [ [1 2 3] [4 5 6] ]</span>
      print(array.shape)<span class="hljs-comment"># Output: (2, 3)</span>
      print(array.dtype)<span class="hljs-comment"># Output: int64</span>
      print(array.size)<span class="hljs-comment"># Output: 6</span>
      print(array.T)<span class="hljs-comment"># Output:[ [1 4] [2 5] [3 6]]</span>
</code></pre>
</li>
</ul>
<h2 id="heading-array-methods">Array Methods</h2>
<p>Some important array methods are <code>flatten()</code> , <code>reshape()</code>, and <code>tolist()</code>.</p>
<pre><code class="lang-python">array = np.array([(<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>), (<span class="hljs-number">4</span>, <span class="hljs-number">5</span>, <span class="hljs-number">6</span>)])

<span class="hljs-comment"># Flatten an array( returns a copy of the array collapsed into one dimension.)</span>
print(array .flatten())  <span class="hljs-comment"># Output: [1 2 3 4 5 6]</span>

<span class="hljs-comment"># Reshape an array( Gives a new shape to an array without changing its data.)</span>
print(array .reshape(<span class="hljs-number">3</span>, <span class="hljs-number">2</span>))  <span class="hljs-comment"># Output: [[1 2] [3 4] [5 6]]</span>

<span class="hljs-comment"># Reshape with inferred dimension</span>
print(array .reshape(<span class="hljs-number">3</span>, <span class="hljs-number">-1</span>))  <span class="hljs-comment"># Output: [[1 2] [3 4] [5 6]]</span>

<span class="hljs-comment"># Convert array to list(Converts an array to a list object.) </span>
print(array .tolist())  <span class="hljs-comment"># Output: [[1, 2, 3], [4, 5, 6]]</span>
</code></pre>
<h2 id="heading-mathematical-functions">Mathematical Functions</h2>
<p>Some common mathematical operations : <code>max()</code>, <code>mean()</code>, <code>min()</code>, <code>std()</code>.</p>
<pre><code class="lang-python">array  = np.array([(<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>), (<span class="hljs-number">4</span>, <span class="hljs-number">5</span>, <span class="hljs-number">6</span>)])

<span class="hljs-comment"># Maximum value</span>
print(array .max())  <span class="hljs-comment"># Output: 6</span>

<span class="hljs-comment"># Mean value</span>
print(array .mean())  <span class="hljs-comment"># Output: 3.5</span>

<span class="hljs-comment"># Minimum value</span>
print(array .min())  <span class="hljs-comment"># Output: 1</span>

<span class="hljs-comment"># Standard deviation</span>
print(array .std())  <span class="hljs-comment"># Output: 1.707825127659933</span>
</code></pre>
<h2 id="heading-indexing-and-slicing">Indexing and Slicing</h2>
<ul>
<li><p>Access individual elements of a NumPy array using indexing and slicing.</p>
</li>
<li><p>Indexing in NumPy is similar to indexing in Python lists, except multiple indices can be used to access elements in multidimensional arrays.</p>
</li>
</ul>
<pre><code class="lang-python">array = np.array([(<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>), (<span class="hljs-number">4</span>, <span class="hljs-number">5</span>, <span class="hljs-number">6</span>)])

<span class="hljs-comment"># Indexing</span>
print(array [<span class="hljs-number">1</span>])  <span class="hljs-comment"># Output: [4 5 6]</span>
print(array [<span class="hljs-number">0</span>, <span class="hljs-number">1</span>])  <span class="hljs-comment"># Output: 2</span>
print(array [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>])  <span class="hljs-comment"># Output: 6</span>

<span class="hljs-comment"># Slicing to access subarrays of a NumPy array</span>
print(array [:, <span class="hljs-number">1</span>:])  <span class="hljs-comment"># Output: [[2 3] [5 6]]</span>
</code></pre>
<h2 id="heading-array-operations">Array Operations</h2>
<p>NumPy arrays support a variety of operations, including mathematical functions and arithmetic, such as element-wise addition and multiplication.</p>
<pre><code class="lang-python">a = np.array([(<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>), (<span class="hljs-number">4</span>, <span class="hljs-number">5</span>, <span class="hljs-number">6</span>)])
b = np.array([[<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>], [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>]])
print(a)         <span class="hljs-comment"># Output: [[1 2 3] [4 5 6]]</span>
print(b)         <span class="hljs-comment"># Output: [[1 2 3] [1 2 3]]</span>
print(a + b)     <span class="hljs-comment"># Output: [[2 4 6] [5 7 9]]</span>
print(a * b)     <span class="hljs-comment"># Output: [[ 1  4  9] [ 4 10 18]]</span>
</code></pre>
<p>Furthermore, there are other crucial <a target="_blank" href="https://numpy.org/doc/stable/reference/routines.math.html#mathematical-functions">mathematical functions</a> that can be applied to individual or multiple arrays.</p>
<h2 id="heading-mutability">Mutability</h2>
<p>NumPy arrays are mutable, though they have certain limitations. For example, you can modify an existing element in an array:</p>
<pre><code class="lang-python"><span class="hljs-comment"># Modify an element</span>
a[<span class="hljs-number">1</span>][<span class="hljs-number">1</span>] = <span class="hljs-number">100</span>
print(a)  <span class="hljs-comment"># Output: [[  1   2   3] [  4 100   6]]</span>

<span class="hljs-comment"># Attempt to add an element (will cause an error)</span>
a[<span class="hljs-number">3</span>] = <span class="hljs-number">100</span>  <span class="hljs-comment"># Uncommenting this will raise an IndexError</span>
</code></pre>
<p>To conclude, NumPy arrays allocate a contiguous block of memory, ensuring fast access and manipulation but restricting the ability to resize after creation.</p>
<p>By mastering these core functionalities, you can leverage NumPy arrays for efficient numerical computing and data manipulation in your projects. Save this guide for quick reference and further practice as you delve deeper into data science and numerical analysis with NumPy.</p>
]]></content:encoded></item><item><title><![CDATA[List comprehension, zip(), & enumerate( )]]></title><description><![CDATA[List comprehension
One of the most useful tools in Python is list comprehension. It is a concise and efficient way to create a new list based on the values in an existing iterable object. List comprehensions take the following form:
my_list = [expres...]]></description><link>https://bitsnotion.com/list-comprehension-zip-enumerate</link><guid isPermaLink="true">https://bitsnotion.com/list-comprehension-zip-enumerate</guid><category><![CDATA[enumerate]]></category><category><![CDATA[list comprehension]]></category><category><![CDATA[zip]]></category><category><![CDATA[Unzip]]></category><category><![CDATA[Python]]></category><category><![CDATA[list]]></category><dc:creator><![CDATA[Nirmal Pandey]]></dc:creator><pubDate>Wed, 03 Apr 2024 18:15:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1717425577665/c7f10e34-d395-4e2e-8423-852d85acf1fb.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-list-comprehension">List comprehension</h2>
<p>One of the most useful tools in Python is <a target="_blank" href="https://docs.python.org/3/tutorial/datastructures.html#list-comprehensions">list comprehension</a>. It is a concise and efficient way to create a new list based on the values in an existing iterable object. List comprehensions take the following form:</p>
<p><code>my_list = [expression for element in iterable if condition]</code></p>
<p><a target="_blank" href="https://docs.python.org/3/tutorial/datastructures.html?highlight=list%20comprehension#list-comprehensions">In this syntax:</a></p>
<ul>
<li><p><strong>expression</strong>: What you want to do with each element. This can be a transformation or any operation.</p>
</li>
<li><p><strong>element</strong>: The variable name that represents each item in the iterable.</p>
</li>
<li><p><strong>iterable</strong>: The sequence (like a list, tuple, string, etc.) you are iterating over.</p>
</li>
<li><p><strong>condition</strong> (optional): Any expression that evaluates to <code>True</code> of <code>False</code>.</p>
</li>
</ul>
<h3 id="heading-some-examples-of-list-comprehensions"><strong>Some examples of List Comprehensions :</strong></h3>
<p><strong>1. Creating a List of Squares:</strong></p>
<pre><code class="lang-python">numbers = [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>]
squared = [x ** <span class="hljs-number">2</span> <span class="hljs-keyword">for</span> x <span class="hljs-keyword">in</span> numbers]
print(squared)  <span class="hljs-comment"># Output: [1, 4, 9, 16, 25]</span>
</code></pre>
<p><strong>2. Filtering Even Numbers:</strong></p>
<pre><code class="lang-python">numbers = [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>]
even = [x <span class="hljs-keyword">for</span> x <span class="hljs-keyword">in</span> numbers <span class="hljs-keyword">if</span> x % <span class="hljs-number">2</span> == <span class="hljs-number">0</span>]
print(even)  <span class="hljs-comment"># Output: [2, 4]</span>
</code></pre>
<p><strong>3. Manipulating Elements with Conditions:</strong></p>
<pre><code class="lang-python">names = [<span class="hljs-string">"Alice"</span>, <span class="hljs-string">"Bob"</span>, <span class="hljs-string">"Charlie"</span>]
formatted_names = [name.upper() <span class="hljs-keyword">if</span> len(name) &gt; <span class="hljs-number">4</span> <span class="hljs-keyword">else</span> name.lower() <span class="hljs-keyword">for</span> name <span class="hljs-keyword">in</span> names]
print(formatted_names)  <span class="hljs-comment"># Output: ['alice', 'BOB', 'CHARLIE']</span>
</code></pre>
<p><strong>4. Flattening a Nested List:</strong></p>
<pre><code class="lang-python">nested_list = [[<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>], [<span class="hljs-number">4</span>, <span class="hljs-number">5</span>, <span class="hljs-number">6</span>], [<span class="hljs-number">7</span>, <span class="hljs-number">8</span>, <span class="hljs-number">9</span>]]
flattened = [x <span class="hljs-keyword">for</span> sublist <span class="hljs-keyword">in</span> nested_list <span class="hljs-keyword">for</span> x <span class="hljs-keyword">in</span> sublist]
print(flattened)  <span class="hljs-comment"># Output: [1, 2, 3, 4, 5, 6, 7, 8, 9]</span>
</code></pre>
<h2 id="heading-zip">Zip( )</h2>
<p>The <code>zip()</code> function is used to combine two or more iterables (like lists or tuples) into a single iterable of tuples. Each tuple contains elements from the input iterables that have the same position.</p>
<p><img src="https://d3c33hcgiwev3.cloudfront.net/imageAssetProxy.v1/WQ6Ugqf7T72HkgvPP_U-JQ_fbb128d8634a40c18ced8dbc582d52f1_cLCJsKs2A-b9zzn3tnZBwGhHLFlR4qXSIc246t6wxfnuxyjzBPkuAvxGXgQn7FsK3yxodNzNiFfu8rvqDcJrFCF1230WJNO6QXSkxByigCBT0jkbc-wKb4pLyMAwArK5ctro1yvgA3IRoqQSSi9N9yZs9wM-KQuNgGGQXcEPuQviW_ZZSV5iu8mAYuZrVxwk8agKMpjvjWTgrpa7E0IkodZvpY8AaZQYnhSlHA?expiry=1717545600000&amp;hmac=k1OazPQUcmC3C-SkUlQceC7kWPexUl3Z3KLQ2g0htwo" alt="An image of a zipper with interlocking teeth, closed on the left and open on the right" /></p>
<pre><code class="lang-python">names = [<span class="hljs-string">'Alice'</span>, <span class="hljs-string">'Bob'</span>, <span class="hljs-string">'Charlie'</span>]
scores = [<span class="hljs-number">85</span>, <span class="hljs-number">92</span>, <span class="hljs-number">78</span>]

combined = zip(names, scores)
print(list(combined))  <span class="hljs-comment"># Output: [('Alice', 85), ('Bob', 92), ('Charlie', 78)]</span>
</code></pre>
<p>In this example, <code>zip()</code> pairs each element from <code>names</code> with the corresponding element from <code>scores</code>, creating a list of tuples. This can be particularly useful for iterating over multiple lists simultaneously.</p>
<h2 id="heading-unzipping">Unzipping</h2>
<p>You can also unzip an object with the <code>*</code> operator. Here’s the syntax:</p>
<pre><code class="lang-python">cities = [(<span class="hljs-string">'New York'</span>, <span class="hljs-number">8419000</span>), (<span class="hljs-string">'Los Angeles'</span>, <span class="hljs-number">3980400</span>), (<span class="hljs-string">'Chicago'</span>, <span class="hljs-number">2716000</span>)]
city_names, populations = zip(*cities)
print(city_names)     <span class="hljs-comment"># Output: ('New York', 'Los Angeles', 'Chicago')</span>
print(populations)    <span class="hljs-comment"># Output: (8419000, 3980400, 2716000)</span>
</code></pre>
<h2 id="heading-enumerate">Enumerate( )</h2>
<p>The <code>enumerate()</code> function adds a counter to an iterable and returns it as an enumerate object. This is extremely useful when you need both the index and the value of elements in a loop.</p>
<pre><code class="lang-python">fruits = [<span class="hljs-string">'apple'</span>, <span class="hljs-string">'banana'</span>, <span class="hljs-string">'cherry'</span>]

<span class="hljs-keyword">for</span> index, fruit <span class="hljs-keyword">in</span> enumerate(fruits):
    print(<span class="hljs-string">f"<span class="hljs-subst">{index}</span>: <span class="hljs-subst">{fruit}</span>"</span>)

<span class="hljs-comment">#Output :</span>
<span class="hljs-string">'''
0: apple
1: banana
2: cherry
'''</span>
</code></pre>
<p>With <code>enumerate()</code>, you no longer need to manage a separate counter variable, making your loop cleaner and more readable.</p>
<p><strong>Key takeaways:</strong></p>
<p>Using <code>zip()</code>, <code>enumerate()</code>, and list comprehensions can significantly enhance code efficiency by minimizing the reliance on traditional loops for data processing. These tools simplify working with iterables, saving time and making data manipulation more dynamic and streamlined. Understanding these common techniques will greatly improve your coding workflow.</p>
]]></content:encoded></item><item><title><![CDATA[Tools and Technologies For Big Data]]></title><description><![CDATA[The era of Big Data has ushered in a new paradigm of data-driven decision-making, revolutionizing industries across the globe. To harness the power of Big Data effectively, organizations rely on a diverse array of tools and technologies that cover da...]]></description><link>https://bitsnotion.com/tools-and-technologies-for-big-data</link><guid isPermaLink="true">https://bitsnotion.com/tools-and-technologies-for-big-data</guid><category><![CDATA[big data]]></category><category><![CDATA[data analysis]]></category><category><![CDATA[tableau]]></category><category><![CDATA[spark]]></category><category><![CDATA[database]]></category><dc:creator><![CDATA[Nirmal Pandey]]></dc:creator><pubDate>Sun, 12 Nov 2023 18:15:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1694849414990/7606e961-be7d-41d2-aa1b-eeb14780756e.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>The era of Big Data has ushered in a new paradigm of data-driven decision-making, revolutionizing industries across the globe. To harness the power of Big Data effectively, organizations rely on a diverse array of tools and technologies that cover data storage and management, data cleansing, data analysis, and data visualization. In this comprehensive guide, we will explore these crucial aspects of Big Data, backed by real-world examples and scenarios.</p>
<h3 id="heading-data-storage-and-management"><strong>Data Storage and Management</strong></h3>
<p>1.1 <strong>Hadoop Distributed File System (HDFS):</strong></p>
<ul>
<li><p>HDFS is a distributed file system designed to store and manage massive volumes of data across clusters of commodity hardware.</p>
</li>
<li><p>It offers fault tolerance and scalability.</p>
<p>  <strong>Real-Time Scenario:</strong></p>
<p>  Storing and processing terabytes of sensor data from smart cities to improve urban planning and resource allocation.</p>
</li>
</ul>
<p>1.2 <strong>Cassandra:</strong></p>
<ul>
<li><p>Cassandra is a distributed NoSQL database known for its scalability and high availability.</p>
</li>
<li><p>It employs a decentralized architecture that distributes data across multiple nodes, ensuring fault tolerance and uninterrupted operations even in the face of hardware failures.</p>
<p>  <strong>Real-Time Scenario:</strong></p>
<p>  In case of IoT Data Management, consider a scenario where a smart city infrastructure generates vast volumes of data from sensors, traffic cameras, and weather stations. Cassandra's scalability and fault tolerance make it an ideal choice to handle the influx of real-time data, ensuring uninterrupted services and analytics for city planners.</p>
</li>
</ul>
<p>1.3 <strong>MongoDb</strong></p>
<ul>
<li><p>MongoDB is a popular NoSQL database recognized for its flexible schema and JSON-like document model.</p>
</li>
<li><p>It allows organizations to store unstructured or semi-structured data while providing robust querying capabilities.</p>
<p>  <strong>Real-Time Scenario:</strong></p>
<p>  In case of Content Management, MongoDB's flexible schema is invaluable. It accommodates diverse content types, such as articles, images, and videos, while enabling efficient querying and indexing for content retrieval and personalization.</p>
</li>
</ul>
<h3 id="heading-data-cleansing"><strong>Data Cleansing</strong></h3>
<p>2.1 <strong>OpenRefine (Google Refine):</strong></p>
<ul>
<li><p>OpenRefine is a data wrangling tool used for data cleaning, transformation, and exploration.</p>
</li>
<li><p>It helps standardize and clean messy data.</p>
<p>  <strong>Real-Time Scenario:</strong></p>
<p>  Standardizing and cleaning customer data with variations in names, addresses, and contact information for a CRM system.</p>
</li>
</ul>
<p>2.2 <strong>Trifacta:</strong></p>
<ul>
<li><p>Trifacta is a data preparation platform that automates data cleansing and transformation tasks.</p>
</li>
<li><p>It uses machine learning to suggest data cleaning operations.</p>
<p>  <strong>Real-Time Scenario:</strong></p>
<p>  Preparing and cleaning unstructured text data, such as customer reviews, to extract sentiment and feedback for product improvements.</p>
</li>
</ul>
<h3 id="heading-data-analysis"><strong>Data Analysis</strong></h3>
<p>3.1 <strong>Apache Spark:</strong></p>
<ul>
<li><p>Apache Spark is a versatile data processing framework supporting batch and real-time data analysis, machine learning, and graph processing.</p>
</li>
<li><p>One of the most significant advantages of Apache Spark is its exceptional speed.</p>
<p>  <strong>Real-Time Scenario:</strong></p>
<p>  Analyzing real-time financial market data to detect anomalies and trigger automated trading decisions.</p>
</li>
</ul>
<p>3.2 <strong>Python (with Pandas and Scikit-Learn):</strong></p>
<ul>
<li><p>Python, along with libraries like Pandas and Scikit-Learn, is widely used for data analysis, statistical modeling, and machine learning.</p>
<p>  <strong>Real-Time Scenario:</strong></p>
<p>  Developing predictive models to forecast customer demand for a retail chain based on historical sales and market trends.</p>
</li>
</ul>
<h3 id="heading-data-visualization"><strong>Data Visualization</strong></h3>
<p>4.1 <strong>Tableau:</strong></p>
<ul>
<li><p>Tableau is a leading data visualization tool that allows users to create interactive dashboards and reports, making data insights accessible.</p>
<p>  <strong>Real-Time Scenario:</strong></p>
<p>  Creating dynamic supply chain dashboards to monitor inventory levels, track deliveries, and optimize logistics operations.</p>
</li>
</ul>
<p>4.2 <strong>Power BI:</strong></p>
<ul>
<li><p>Power BI is a Microsoft business intelligence tool for data visualization, analytics, and reporting, with seamless integration into the Microsoft ecosystem.</p>
<p>  <strong>Real-Time Scenario:</strong></p>
<p>  Visualizing and sharing sales performance data across a retail organization to identify top-performing products and regions.</p>
</li>
</ul>
<p>In conclusion, these tools and technologies are instrumental in managing, cleansing, analyzing, and visualizing data to extract actionable insights. Real-world scenarios demonstrate the practical application of these tools across various industries, showcasing their transformative power in enabling data-driven decision-making and innovation. Staying abreast of these tools and leveraging them effectively is essential for organizations to thrive in the data-centric landscape of today.</p>
]]></content:encoded></item><item><title><![CDATA[Django Models]]></title><description><![CDATA[Django models are a fundamental component of Django web applications, offering a simplified and pythonic way to define the structure of your data. Acting as Python classes, Django models enable seamless interactions with the underlying database. With...]]></description><link>https://bitsnotion.com/django-models</link><guid isPermaLink="true">https://bitsnotion.com/django-models</guid><category><![CDATA[Django]]></category><category><![CDATA[Databases]]></category><category><![CDATA[crud]]></category><category><![CDATA[database migrations]]></category><dc:creator><![CDATA[Nirmal Pandey]]></dc:creator><pubDate>Mon, 24 Jul 2023 18:15:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1690002478992/25dd6fef-b178-46ba-a82d-ffbd91b66448.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Django models are a fundamental component of Django web applications, offering a simplified and pythonic way to define the structure of your data. Acting as Python classes, Django models enable seamless interactions with the underlying database. With models, developers can work with data more intuitively, abstracting away the complexities of SQL queries and database management.</p>
<ul>
<li><p>Each model is a Python class that <code>subclasses django.db.models.Model.</code></p>
</li>
<li><p>Each attribute of the model represents a database field.</p>
</li>
</ul>
<p><strong>Example :</strong></p>
<pre><code class="lang-python"><span class="hljs-keyword">from</span> django.db <span class="hljs-keyword">import</span> models

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Post</span>(<span class="hljs-params">models.Model</span>):</span>
    title = models.CharField(max_length=<span class="hljs-number">200</span>)
    description = models.TextField()

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__str__</span>(<span class="hljs-params">self</span>):</span>
        <span class="hljs-keyword">return</span> self.title
</code></pre>
<p>In this example, the "Post" model defines fields for title, description, and image. The <code>CharField</code> represents a character field with a maximum length of 200 characters, while the <code>TextField</code> represents a longer text field. The <code>__str__</code> method returns the title of the post for better readability.</p>
<p><strong>Corresponding schema</strong></p>
<div class="hn-table">
<table>
<thead>
<tr>
<td><strong>Field Name</strong></td><td><strong>Data Type</strong></td><td><strong>Constraints</strong></td></tr>
</thead>
<tbody>
<tr>
<td>id</td><td>AutoField (Primary Key)</td><td>Automatically generated and unique</td></tr>
<tr>
<td>title</td><td>CharField</td><td>Maximum length: 200</td></tr>
<tr>
<td>description</td><td>TextField</td></tr>
</tbody>
</table>
</div><h3 id="heading-databases-in-django"><strong>Databases in Django</strong></h3>
<p>In Django, the default database is set up to use SQLite as the database engine.</p>
<ul>
<li><p>In your project's "<a target="_blank" href="http://settings.py">settings.py</a>" file, the default database configuration is typically set up like this:</p>
<pre><code class="lang-python">  DATABASES = {
      <span class="hljs-string">'default'</span>: {
          <span class="hljs-string">'ENGINE'</span>: <span class="hljs-string">'django.db.backends.sqlite3'</span>,   <span class="hljs-comment"># SQLite database engine</span>
          <span class="hljs-string">'NAME'</span>: BASE_DIR / <span class="hljs-string">'db.sqlite3'</span>,          <span class="hljs-comment"># Database file path</span>
      }
  }
</code></pre>
</li>
</ul>
<p><strong>Explanation of the configuration:</strong></p>
<ol>
<li><p><code>ENGINE</code>: This specifies the database engine to be used, which is set to <code>'django.db.backends.sqlite3'</code> for SQLite.</p>
</li>
<li><p><code>NAME</code>: This indicates the file path where the SQLite database file will be created and stored.</p>
</li>
<li><p>By default, it is set to <code>'db.sqlite3'</code>, and it is placed in the project's base directory (<code>BASE_DIR</code>). You can change the name or location of the SQLite database file by modifying this setting.</p>
</li>
</ol>
<ul>
<li><p>When connecting to other databases extra connection parameters will be required, let's take an example of PostgreSQL</p>
<pre><code class="lang-python">  DATABASES = {
    <span class="hljs-string">'default'</span>: {
        <span class="hljs-string">'ENGINE'</span>: <span class="hljs-string">'django.db.backends.postgresql'</span>,
        <span class="hljs-string">'NAME'</span>: <span class="hljs-string">'database_name'</span>,
        <span class="hljs-string">'USER'</span>: <span class="hljs-string">'database_user'</span>,
        <span class="hljs-string">'PASSWORD'</span>: <span class="hljs-string">'database_password'</span>,
        <span class="hljs-string">'HOST'</span>: <span class="hljs-string">'127.0.0.1'</span>,
        <span class="hljs-string">'PORT'</span>: <span class="hljs-string">'5432'</span>,
    }
  }
</code></pre>
</li>
</ul>
<h3 id="heading-django-migrations"><strong>Django Migrations</strong></h3>
<p>Whenever changes are made to the models in our Django project, we need to execute two commands: <code>makemigrations</code> and <code>migrate</code>.</p>
<ul>
<li><code>makemigrations</code> generates SQL commands for both preinstalled apps and newly created app models that are added to the installed apps.</li>
</ul>
<p>On the other hand, <code>migrate</code> applies these SQL commands to the database, making the necessary changes.</p>
<pre><code class="lang-python"><span class="hljs-comment">#create new database migration files</span>
Python manage.py makemigrations
</code></pre>
<pre><code class="lang-python"> <span class="hljs-comment">#this create table in the database</span>
Python manage.py migrate
</code></pre>
<h3 id="heading-crud-operation-from-admin-interface">Crud operation from Admin interface</h3>
<p>For this , First I need to register my model in <code>admin.py</code></p>
<pre><code class="lang-python"><span class="hljs-keyword">from</span> django.contrib <span class="hljs-keyword">import</span> admin
<span class="hljs-keyword">from</span> .models <span class="hljs-keyword">import</span> Post

admin.site.register(Post)
</code></pre>
<blockquote>
<p>After you register this , then you can do CRUD operation from Django admin interface.</p>
</blockquote>
<p>While Django's admin interface provides a user-friendly way to interact with data, the Django shell offers a powerful command-line interface to manage your models and database.</p>
<h3 id="heading-performing-various-crud-operation-from-shell">Performing various crud operation from shell</h3>
<p>To access the Django shell, open your terminal or command prompt, navigate to your Django project directory, and run the following command:</p>
<pre><code class="lang-python">python manage.py shell
</code></pre>
<blockquote>
<p>This command open shell terminal where you can perform data operations.</p>
</blockquote>
<ol>
<li><p><strong>Creating Records</strong></p>
<pre><code class="lang-python"> &gt;&gt;&gt;&gt; new_post = Post(
          title = <span class="hljs-string">"BitsNotion"</span>,  
          description = <span class="hljs-string">"Post Description"</span>,
          )
 &gt;&gt;&gt; new_post.save()<span class="hljs-comment">#Save data to database</span>
</code></pre>
</li>
<li><p><strong>Reading Records</strong></p>
<p> To retrieve record from <code>Post</code> model .We can perform various operations.</p>
<p> <strong>Retrieve all data</strong></p>
<pre><code class="lang-python"> all_posts = Post.objects.all()
</code></pre>
<p> <strong>Retrieve a specific post by its primary key (id)</strong></p>
<pre><code class="lang-python"> post = Post.objects.get(id=<span class="hljs-number">1</span>)
</code></pre>
<p> <strong>Filter posts based on specific criteria (e.g., title)</strong></p>
<pre><code class="lang-python"> query_set = Post.objects.filter(title=<span class="hljs-string">'BitsNotion'</span>)
</code></pre>
</li>
<li><p>Updating Records</p>
<pre><code class="lang-python"> <span class="hljs-comment"># Retrieve the post you want to update</span>
 post = Post.objects.get(id=<span class="hljs-number">1</span>)
 post.title = <span class="hljs-string">'Updated Post Title'</span>
 post.save()
</code></pre>
</li>
<li><p>Deleting Records</p>
<pre><code class="lang-python"> <span class="hljs-comment"># Retrieve the post you want to delete</span>
 post = Post.objects.get(id=<span class="hljs-number">1</span>)
 post.delete()<span class="hljs-comment">#delete your post</span>
</code></pre>
</li>
</ol>
<h3 id="heading-various-model-fields-list">Various model fields list</h3>
<div class="hn-table">
<table>
<thead>
<tr>
<td><strong>Field Type</strong></td><td><strong>Title</strong></td><td><strong>Description</strong></td></tr>
</thead>
<tbody>
<tr>
<td>AutoField</td><td>Auto-Incrementing Primary Key</td><td>An automatically incrementing field that serves as the primary key for each record. It assigns a unique integer value to each new record automatically.</td></tr>
<tr>
<td>BigIntegerField</td><td>64-bit Integer Field</td><td>A field that stores large numerical values represented by 64-bit integers. Useful for handling very large numbers.</td></tr>
<tr>
<td>BooleanField</td><td>True/False Field</td><td>A field to represent true/false values or boolean choices. It stores <code>True</code> or <code>False</code> values to indicate binary choices.</td></tr>
<tr>
<td>CharField</td><td>Character Field</td><td>A field for storing short strings with a fixed maximum length. Commonly used for names, titles, or other short pieces of text.</td></tr>
<tr>
<td>DateField</td><td>Date Field</td><td>A field to store dates without the time component. It can represent dates ranging from 1000-01-01 to 9999-12-31.</td></tr>
<tr>
<td>DateTimeField</td><td>Date and Time Field</td><td>A field to store both dates and time with microsecond precision. It represents dates and times ranging from 1000-01-01 to 9999-12-31.</td></tr>
<tr>
<td>DecimalField</td><td>Decimal Field</td><td>A field for storing decimal numbers with fixed-precision. It is useful for handling financial data or other precise numeric values.</td></tr>
<tr>
<td>EmailField</td><td>Email Address Field</td><td>A field to store valid email addresses. It validates input to ensure it follows the correct email format.</td></tr>
<tr>
<td>FileField</td><td>File Upload Field</td><td>A field to upload and store files. It can be used to handle file uploads, such as images, documents, or other files.</td></tr>
<tr>
<td>FloatField</td><td>Floating-Point Number Field</td><td>A field for storing floating-point numbers. It can represent real numbers with decimal fractions, e.g., 3.14.</td></tr>
<tr>
<td>ImageField</td><td>Image Upload Field</td><td>Similar to <code>FileField</code>, but it is specifically used for uploading and storing image files.</td></tr>
<tr>
<td>IntegerField</td><td>Integer Field</td><td>A field for storing whole numbers without any decimal places. It represents 32-bit signed integers.</td></tr>
<tr>
<td>TextField</td><td>Text Field</td><td>A field for storing long text strings with unlimited length. It is useful for storing large pieces of text, such as articles or descriptions.</td></tr>
<tr>
<td>URLField</td><td>URL Field</td><td>A field to store valid URLs. It validates input to ensure it follows the correct URL format.</td></tr>
<tr>
<td>UUIDField</td><td>Universally Unique Identifier Field</td><td>A field to store universally unique identifiers (UUIDs). UUIDs are 128-bit unique identifiers, often used to ensure uniqueness in distributed systems.</td></tr>
</tbody>
</table>
</div>]]></content:encoded></item><item><title><![CDATA[Getting Started with Django]]></title><description><![CDATA[In the expansive fields of web development frameworks, Django stands out as a powerful and favored option for creating robust web applications. As an open-source Python web framework, Django was specifically designed to simplify the web development p...]]></description><link>https://bitsnotion.com/getting-started-with-django</link><guid isPermaLink="true">https://bitsnotion.com/getting-started-with-django</guid><category><![CDATA[Django]]></category><category><![CDATA[Python]]></category><category><![CDATA[Python 3]]></category><dc:creator><![CDATA[Nirmal Pandey]]></dc:creator><pubDate>Sat, 01 Jul 2023 12:29:41 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1689938840749/db886326-b23a-4270-91e1-9f16517a4146.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In the expansive fields of web development frameworks, Django stands out as a powerful and favored option for creating robust web applications. As an open-source Python web framework, Django was specifically designed to simplify the web development process while adhering to the principle of <strong>"don't repeat yourself" (DRY)</strong>. Its focus on efficiency, scalability, and security has captured the hearts of developers worldwide.</p>
<h1 id="heading-features">Features</h1>
<p>Django boasts an array of distinctive features that set it apart:</p>
<ol>
<li><p><strong>Scalability</strong>: The modern world demands web applications that can handle an ever-increasing number of users and data. Django's scalability is a result of its ability to efficiently manage database queries, handle caching, and optimize code execution. This scalability makes Django suitable for applications ranging from small startups to large-scale enterprises.</p>
</li>
<li><p><strong>Security</strong>: Security is of paramount importance in the modern digital landscape, and Django takes security seriously. It comes with built-in features to prevent common web vulnerabilities like SQL injection, cross-site scripting (XSS), and cross-site request forgery (CSRF). Additionally, Django's authentication system allows for secure user management.</p>
</li>
<li><p><strong>Versatility</strong>: Django's versatility is evident in its ability to support various types of web applications. Whether it's a content-heavy website, an e-commerce platform, a social media network, or an API-centric application, Django can handle diverse requirements.</p>
</li>
<li><p><strong>Community and Documentation</strong>: Django boasts an active and robust community of developers, contributing to its constant growth and improvement. The official documentation is extensive, well-maintained, and beginner-friendly, making it easier for developers to learn and utilize the framework effectively.</p>
</li>
<li><p><strong>Django REST Framework</strong>: In the modern world of web development, APIs (Application Programming Interfaces) play a vital role in enabling seamless interactions between different services and platforms. Django's integration with the Django REST Framework simplifies the process of building powerful and scalable Web APIs.</p>
</li>
</ol>
<h1 id="heading-setting-up-a-django-project">Setting Up a Django Project</h1>
<h3 id="heading-creating-a-virtual-environment">Creating a Virtual Environment</h3>
<p>A virtual environment allows you to create an isolated Python environment for your project, ensuring that the dependencies you install don't interfere with other projects on your system.</p>
<pre><code class="lang-bash"><span class="hljs-comment"># On Windows</span>
python -m venv project_env

<span class="hljs-comment"># On macOS and Linux</span>
python3 -m venv project_env
</code></pre>
<p>This will create a new directory called <code>project_env</code> containing the virtual environment.</p>
<blockquote>
<p>To activate virtual environment in your project run <code>project_env\Scripts\activate</code> on Windows or <code>source project_env/bin/activate</code> on Mac OS X or Linux will activate your virtual environment.</p>
</blockquote>
<p>Now that the virtual environment is set up, it's time to install Django. Within your virtual environment, use pip to install Django:</p>
<pre><code class="lang-bash"><span class="hljs-comment"># On Windows, macOS, and Linux</span>
(project_env) ~/pip install django
</code></pre>
<h3 id="heading-creating-the-django-project"><strong>Creating the Django Project</strong></h3>
<p>With Django installed, you can create a new Django project. Navigate to the folder where you want to create your project, and run the following command:</p>
<pre><code class="lang-bash">(project_env) ~/django-admin startproject myproject
</code></pre>
<p>This will create a new directory named <code>myproject</code>, which will be the root of your Django project.Inside the <code>myproject</code> directory, you'll find the initial folder structure of your Django project:</p>
<pre><code class="lang-bash">myproject/
|-- manage.py
|-- myproject/
    |-- __init__.py
    |-- asgi.py
    |-- settings.py
    |-- urls.py
    |-- wsgi.py
</code></pre>
<ol>
<li><p><a target="_blank" href="http://manage.py"><code>manage.py</code></a> file is a command-line utility that allows you to interact with your project.</p>
</li>
<li><p><a target="_blank" href="http://settings.py"><code>settings.py</code></a> file contains the configuration of your website.</p>
</li>
<li><p><a target="_blank" href="http://asgi.py"><code>asgi.py</code></a> configures the application to handle asynchronous web servers using the ASGI (Asynchronous Server Gateway Interface) specification.</p>
</li>
<li><p><a target="_blank" href="http://wsgi.py"><code>wsgi.py</code></a> configures the application to work with traditional synchronous web servers using the WSGI (Web Server Gateway Interface) standard.</p>
</li>
</ol>
<blockquote>
<p>Django provides a pre-built and pre-configured development server that you can easily run using the command <code>python</code> <a target="_blank" href="http://manage.py"><code>manage.py</code></a> <code>runserver</code>. When you navigate to the locally deployed Django address, typically at <a target="_blank" href="http://127.0.0.1:8000/">http://127.0.0.1:8000</a>.</p>
</blockquote>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1689938515440/88997aa8-3d64-44ba-95d0-4b61de835577.png" alt class="image--center mx-auto" /></p>
<blockquote>
<p>You have successfully run your Django first application.But you may be curious to see some custom output by your own.Let's do that.</p>
</blockquote>
<h3 id="heading-creating-django-apps">Creating Django apps</h3>
<p>In Django, a web application is typically divided into smaller components called "apps." Each app handles a specific functionality or set of related features within the overall project.</p>
<p>To create a new app, navigate to the root directory of your Django project using the terminal (where the <a target="_blank" href="http://manage.py"><code>manage.py</code></a> file is located) and run the following command:</p>
<pre><code class="lang-bash">python manage.py startapp &lt;app_name&gt;
<span class="hljs-comment">#For example </span>
(project_env) ~/python manage.py startapp hello_app
</code></pre>
<p>This command will create a new directory named <code>hello_app</code>, which contains the initial structure of the app:</p>
<pre><code class="lang-python">hello_app/
|-- migrations/
|   |-- __init__.py
|-- __init__.py
|-- admin.py
|-- apps.py
|-- models.py
|-- tests.py
|-- views.py
</code></pre>
<p><strong>This will create another directory called hello_app with several files:</strong></p>
<ul>
<li><p><code>__init__.py</code> tells Python to treat the directory as a Python package.</p>
</li>
<li><p><a target="_blank" href="http://admin.py"><code>admin.py</code></a> contains settings for the Django admin pages.</p>
</li>
<li><p><a target="_blank" href="http://apps.py"><code>apps.py</code></a> contains settings for the application configuration.</p>
</li>
<li><p><a target="_blank" href="http://models.py"><code>models.py</code></a> contains a series of classes that Django’s ORM converts to database tables.</p>
</li>
<li><p><a target="_blank" href="http://tests.py"><code>tests.py</code></a> contains test classes.</p>
</li>
<li><p><a target="_blank" href="http://views.py"><code>views.py</code></a> contains functions and classes that handle what data is displayed in the HTML templates.</p>
</li>
</ul>
<h3 id="heading-including-the-app-in-settings">Including the App in Settings</h3>
<p>After creating the app, you need to include it in the project's settings. Open the <a target="_blank" href="http://settings.py"><code>settings.py</code></a> file inside the <code>myproject</code> directory and locate the <code>INSTALLED_APPS</code> list. Add your app name (hello_app) to the list:</p>
<pre><code class="lang-python">INSTALLED_APPS = [
    <span class="hljs-comment"># ...</span>
    <span class="hljs-string">'hello_app'</span>,
    <span class="hljs-comment"># ...</span>
]
</code></pre>
<blockquote>
<p>By adding your app to the <code>INSTALLED_APPS</code> list, Django recognizes the app and includes it in the project.</p>
</blockquote>
<h3 id="heading-writing-the-hello-world-view">Writing the "Hello, World!" View</h3>
<p>In Django, views handle the logic for processing HTTP requests and returning responses. Let's create a simple "Hello, World!" view inside the <a target="_blank" href="http://views.py"><code>views.py</code></a> file of the hello_app:</p>
<pre><code class="lang-python"><span class="hljs-comment"># hello_app/views.py</span>
<span class="hljs-keyword">from</span> django.http <span class="hljs-keyword">import</span> HttpResponse

<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">hello_world</span>(<span class="hljs-params">request</span>):</span>
    html_content = <span class="hljs-string">"&lt;h1&gt;Hello, World!&lt;/h1&gt;"</span>
    <span class="hljs-keyword">return</span> HttpResponse(html_content)
</code></pre>
<h3 id="heading-creating-a-url-mapping">Creating a URL Mapping</h3>
<p>Now that we have our view defined, we need to map it to a URL. Open the <a target="_blank" href="http://urls.py"><code>urls.py</code></a> file inside the <code>hello_app</code> directory and add the following code:</p>
<pre><code class="lang-python"><span class="hljs-comment"># hello_app/urls.py</span>

<span class="hljs-keyword">from</span> django.urls <span class="hljs-keyword">import</span> path
<span class="hljs-keyword">from</span> . <span class="hljs-keyword">import</span> views

urlpatterns = [
    path(<span class="hljs-string">'hello/'</span>, views.hello_world, name=<span class="hljs-string">'hello_app'</span>),
]
</code></pre>
<blockquote>
<p>In this code, we import the <code>hello_world</code> view we created and map it to the URL path <code>/hello/</code>.</p>
</blockquote>
<h3 id="heading-include-the-app-urls-in-the-project">Include the App URLs in the Project</h3>
<p>To make the app's URLs accessible within the project, open the <a target="_blank" href="http://urls.py"><code>urls.py</code></a> file of the project (located in the <code>myproject</code> directory) and include the app's URLs using the <code>include</code> function:</p>
<pre><code class="lang-python"><span class="hljs-comment"># myproject/urls.py</span>

<span class="hljs-keyword">from</span> django.contrib <span class="hljs-keyword">import</span> admin
<span class="hljs-keyword">from</span> django.urls <span class="hljs-keyword">import</span> path, include

urlpatterns = [
    path(<span class="hljs-string">'admin/'</span>, admin.site.urls),
    path(<span class="hljs-string">'hello_app/'</span>, include(<span class="hljs-string">'hello_app.urls'</span>)),  <span class="hljs-comment"># Include the app's URLs</span>
]
</code></pre>
<blockquote>
<p>Now, when you access <code>127.0.0.1:8000/hello_app/hello/</code> .You will see below output:</p>
</blockquote>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1689938132085/a24228e1-97d4-48a1-98bc-1e16290bf8c7.png" alt class="image--center mx-auto" /></p>
<blockquote>
<p>Congratulations! You've successfully set up a Django project from scratch. Now you can start building your web application using Django's powerful features and elegant design.</p>
</blockquote>
]]></content:encoded></item><item><title><![CDATA[Deployment Git with a VPS]]></title><description><![CDATA[Git is a powerful version control system that allows developers to efficiently manage their code repositories and collaborate seamlessly with team members. In this step-by-step guide, we will walk you through the process of setting up and using Git i...]]></description><link>https://bitsnotion.com/deployment-git-with-a-vps</link><guid isPermaLink="true">https://bitsnotion.com/deployment-git-with-a-vps</guid><category><![CDATA[GitHub]]></category><category><![CDATA[Git]]></category><category><![CDATA[vps]]></category><category><![CDATA[ssh-keygen]]></category><category><![CDATA[SSH Git]]></category><dc:creator><![CDATA[Nirmal Pandey]]></dc:creator><pubDate>Tue, 27 Jun 2023 13:49:15 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1689860768115/bfc2f86a-72aa-4cad-ad92-54a77aae7c4e.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Git is a powerful version control system that allows developers to efficiently manage their code repositories and collaborate seamlessly with team members. In this step-by-step guide, we will walk you through the process of setting up and using Git in your VPS server in an easy and beginner-friendly way.</p>
<h2 id="heading-installing-and-configuring-git"><strong>Installing and configuring git</strong></h2>
<ol>
<li><p><strong>Connect to Your VPS Server First</strong>, log in to your VPS server using SSH.</p>
<pre><code class="lang-python"> ssh your_username@your_server_ip
</code></pre>
</li>
<li><p><strong>Install Git:</strong> Most VPS servers come with Git pre-installed, but it's always good to verify. To install Git, use the package manager specific to your server's operating system.</p>
<pre><code class="lang-bash"> <span class="hljs-comment"># on Ubuntu/Debian</span>
 sudo apt-get update
 sudo apt-get install git

 <span class="hljs-comment">#On CentOS/RHEL</span>
 sudo yum install git
</code></pre>
</li>
<li><p><strong>Configure Git:</strong></p>
<p> Before you start using Git, you need to configure your identity. Replace the placeholders with your own name and email address:</p>
<pre><code class="lang-bash"> git config --global user.name <span class="hljs-string">"Your Name"</span>
 git config --global user.email <span class="hljs-string">"youremail@example.com"</span>
</code></pre>
</li>
<li><p><strong>Check your configuration</strong></p>
<pre><code class="lang-bash"> git config --list
</code></pre>
<p> The <strong>git config –list</strong> command should return the configuration you added</p>
<pre><code class="lang-bash"> user.name=YourUserName
 user.email=example@example.com
</code></pre>
</li>
</ol>
<h2 id="heading-using-git-basic-command">Using Git Basic Command</h2>
<ol>
<li><p>Create the Project Directory: First, create a directory for your project. You can do this using the <code>mkdir</code> command:</p>
<pre><code class="lang-bash"> mkdir project
</code></pre>
</li>
</ol>
<ol>
<li><p>Create Files for the Project: Navigate into the <code>project1</code> directory and create some files and a sub-directory:</p>
<pre><code class="lang-bash"> $ <span class="hljs-built_in">cd</span> project
 $ touch file
</code></pre>
</li>
</ol>
<ol>
<li><p>Initialize Git in the Project Directory: Next, you need to initialize a Git repository in the <code>project1</code> directory using the <code>git init</code> command:</p>
<pre><code class="lang-bash"> git init
</code></pre>
</li>
</ol>
<p>This command initializes an empty Git repository in the <code>project</code> directory, allowing Git to track changes in the files.</p>
<ol>
<li><p>Add Files to the Repository:</p>
<pre><code class="lang-bash">  git add .
</code></pre>
</li>
</ol>
<ol>
<li><p>Make Your Initial Commit: After adding the files, it's time to make your initial commit. A commit is a snapshot of the changes you've made to the project. Each commit should have a meaningful commit message describing the changes.</p>
<pre><code class="lang-bash"> git commit -m <span class="hljs-string">"Initial Commit"</span>
</code></pre>
<p> The <code>-m</code> flag allows you to specify the commit message directly in the command. In this case, we use "Initial Commit" to indicate that this is the first commit for the project.</p>
</li>
</ol>
<h2 id="heading-adding-ssh-access-to-github-from-your-vps">Adding SSH access to GitHub from your VPS</h2>
<ol>
<li><p><strong>Check if you already have an SSH key pair by running:</strong></p>
<pre><code class="lang-python"> ls -al ~/.ssh
</code></pre>
</li>
<li><p><strong>Generate SSH Key Pair on VPS:</strong> Log in to your VPS via SSH, open a terminal, and run the following command to generate an SSH key pair:</p>
<pre><code class="lang-python"> ssh-keygen -t rsa -b <span class="hljs-number">4096</span> -C <span class="hljs-string">"your_email@example.com"</span>
</code></pre>
</li>
<li><p><strong>View and Copy Public Key:</strong> After generating the keys, run the following command to display your public key:</p>
<pre><code class="lang-python"> cat ~/.ssh/id_rsa.pub
</code></pre>
<p> Copy the entire output of the command, which is your public key.</p>
</li>
<li><p><strong>Add Public Key to GitHub:</strong></p>
<ol>
<li><p>Click on your profile picture in the upper right</p>
</li>
<li><p>Select <strong>settings</strong></p>
</li>
<li><p>Click on <strong>SSH and GPG keys</strong></p>
</li>
<li><p>Click on the <strong>“Create SSH Key” button</strong></p>
</li>
<li><p>Give the key a <strong>“title”</strong> to help you identify it</p>
</li>
<li><p>Paste the public key into the <strong>“key” field</strong></p>
</li>
<li><p>Save the <strong>key</strong></p>
</li>
</ol>
</li>
<li><p><strong>Test SSH Connection:</strong> To test if your SSH connection is working, run the following command in the terminal of your VPS:</p>
<pre><code class="lang-python"> ssh -T git@github.com
</code></pre>
<p> You should see a message like "Hi username! You've successfully authenticated, but GitHub does not provide shell access."</p>
</li>
<li><p><strong>Update Git Configuration:</strong> To ensure Git uses SSH for pushing and pulling from GitHub, configure it to use the SSH URL. Run the following commands in your VPS terminal:</p>
<pre><code class="lang-python"> git config --<span class="hljs-keyword">global</span> user.email <span class="hljs-string">"your_email@example.com"</span>
 git config --<span class="hljs-keyword">global</span> user.name <span class="hljs-string">"Your Name"</span>
 git remote remote add origin git@github.com:your-username/your-repo.git
</code></pre>
</li>
</ol>
<p>Now, your VPS should be set up to use SSH for interacting with your GitHub repository. Now , you can <strong>clone, push, and pull</strong> from GitHub using SSH without needing to enter your username and password each time.</p>
]]></content:encoded></item><item><title><![CDATA[Nginx vs Apache]]></title><description><![CDATA[Nginx and Apache are both widely used open-source web servers designed to serve web pages and applications. Let's take a closer look at the differences between the two:
History

Apache: First released in 1995, Apache quickly gained popularity due to ...]]></description><link>https://bitsnotion.com/nginx-vs-apache</link><guid isPermaLink="true">https://bitsnotion.com/nginx-vs-apache</guid><category><![CDATA[nginx]]></category><category><![CDATA[apache]]></category><category><![CDATA[server]]></category><category><![CDATA[event-driven-architecture]]></category><dc:creator><![CDATA[Nirmal Pandey]]></dc:creator><pubDate>Mon, 19 Jun 2023 12:27:10 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1689851260511/e402fef8-22f9-4f08-b33f-915cbad07741.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Nginx and Apache are both widely used open-source web servers designed to serve web pages and applications. Let's take a closer look at the differences between the two:</p>
<h2 id="heading-history">History</h2>
<ul>
<li><p><strong>Apache</strong>: First released in 1995, Apache quickly gained popularity due to its flexibility and support for .htaccess configuration files.</p>
</li>
<li><p><strong>Nginx</strong>: Introduced in 2004, Nginx aimed to overcome Apache's performance limitations by focusing on being lightweight, fast, and efficient.</p>
</li>
</ul>
<h2 id="heading-architecture">Architecture</h2>
<p>When comparing <strong>Apache and Nginx</strong>, their fundamental difference lies in their design architecture, which dictates how they handle connections, traffic, and respond to various traffic conditions.</p>
<p><strong>Apache</strong></p>
<ul>
<li><p>Apache employs a <strong>process-driven approach</strong>, which means it creates a new thread for each incoming request.</p>
</li>
<li><p>It offers a variety of processing modules with different algorithms for handling requests, providing flexibility in choosing the right approach for different server needs.</p>
</li>
<li><p>However, this architecture can lead to resource-intensive operations, potentially causing performance issues such as slow speed.</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1689853662842/21c5ac58-729a-4890-9ae4-edc1b509e613.jpeg" alt class="image--center mx-auto" /></p>
</li>
</ul>
<p><strong>Nginx</strong></p>
<ul>
<li><p>On the other hand, Nginx adopts an <strong>event-driven approach</strong>, dealing with requests asynchronously within one processing thread.</p>
</li>
<li><p>It utilizes a non-blocking event-driven connection handling algorithm, allowing it to efficiently manage thousands of connections simultaneously.</p>
</li>
<li><p>This event-driven architecture makes Nginx fast and resource-efficient, suitable for low-power systems and handling heavy loads with ease.</p>
<p>  <img src="https://miro.medium.com/v2/resize:fit:700/0*qTRY05aZ0uR455tW" alt /></p>
</li>
</ul>
<h2 id="heading-performance">Performance</h2>
<ul>
<li><p>Nginx uses an asynchronous event-driven architecture, making it highly scalable and resource-efficient. It can handle a larger number of requests using fewer system resources.</p>
</li>
<li><p>Nginx is particularly adept at serving static files, outperforming Apache in many benchmarks in this area.</p>
</li>
<li><p>Apache's multi-processing architecture consumes more resources, though it has improved over time, Nginx still maintains a performance advantage.</p>
</li>
</ul>
<h2 id="heading-configuration">Configuration</h2>
<ul>
<li><p>Apache utilizes .htaccess files for directory-level configuration, providing flexibility for individual directories. However, this can impact performance due to the need for file checks on each request.</p>
<pre><code class="lang-python">  &lt;VirtualHost *:<span class="hljs-number">80</span>&gt;
      ServerName domain.com
      ScriptAlias /myscript /var/www/html/myscript.php
      <span class="hljs-comment"># Other configurations for the site...</span>
  &lt;/VirtualHost&gt;
</code></pre>
</li>
<li><p>Nginx uses a centralized configuration with server blocks and location blocks, resulting in better performance and a more streamlined configuration process.</p>
<pre><code class="lang-python">  server {
    listen       <span class="hljs-number">80</span>; 
    server_name  domain.com;

    location / {
      root   /var/www/domain.com/html;
      index  index.html index.htm;
    }
  }
</code></pre>
</li>
</ul>
<h2 id="heading-caching">Caching</h2>
<ul>
<li><p>Nginx comes with built-in caching capabilities that are easy to configure and perform well.</p>
</li>
<li><p>Apache relies on external caching solutions such as Varnish to achieve similar caching performance.</p>
</li>
</ul>
<h2 id="heading-modules">Modules</h2>
<ul>
<li><p>Apache boasts a robust module system, allowing for easy installation and enabling/disabling of modules after installation, providing great flexibility.</p>
</li>
<li><p>Nginx modules must be enabled during compilation, making the module system less flexible but potentially more secure.</p>
</li>
</ul>
<p>In summary, Nginx is often a preferred choice for performance-critical applications due to its efficient and scalable architecture, especially excelling at serving static files. On the other hand, Apache remains popular for its flexibility and extensive module system, making it suitable for a wide range of use cases.</p>
]]></content:encoded></item><item><title><![CDATA[Horizontal scaling and Vertical scaling]]></title><description><![CDATA[Data scalability is crucial for the success of software applications in the dynamic digital landscape. It allows databases to grow and adapt to changing demands, ensuring performance and flexibility.
We will explore horizontal and vertical scaling, t...]]></description><link>https://bitsnotion.com/horizontal-scaling-and-vertical-scaling</link><guid isPermaLink="true">https://bitsnotion.com/horizontal-scaling-and-vertical-scaling</guid><category><![CDATA[vertical scaling]]></category><category><![CDATA[horizontal scaling]]></category><category><![CDATA[scalability]]></category><dc:creator><![CDATA[Nirmal Pandey]]></dc:creator><pubDate>Mon, 05 Jun 2023 13:14:16 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1688044371786/8a3ed292-afd7-4a85-a71c-753fe8ecc61a.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Data scalability is crucial for the success of software applications in the dynamic digital landscape. It allows databases to grow and adapt to changing demands, ensuring performance and flexibility.</p>
<p>We will explore horizontal and vertical scaling, their pros and cons, empowering you to make informed decisions for effective database scaling.</p>
<h3 id="heading-understanding-data-scalability">Understanding Data Scalability:</h3>
<p>Data scalability enables databases to handle increased workloads by expanding or reducing their capacity based on application usage. It ensures efficient processing of large data volumes, supports growing user bases, and maintains optimal performance under varying workloads.</p>
<h3 id="heading-horizontal-scaling-scale-out">Horizontal Scaling (Scale-Out):</h3>
<p>Horizontal scaling, also known as scale-out, involves adding more database nodes or servers to distribute the workload and handle increased traffic. Instead of expanding the capacity of individual servers, horizontal scaling focuses on scaling the entire system by adding more nodes.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1688043468360/991ccbf1-ffd3-43b9-9056-850b4560cf5e.png" alt /></p>
<p><strong>Advantages of Horizontal Scaling:</strong></p>
<ol>
<li><p>Easy to Upgrade: You can incrementally increase capacity as needed.</p>
</li>
<li><p>Cost-Effective: Horizontal scaling often involves using commodity hardware and open-source software, making it a cost-effective solution for scaling your database.</p>
</li>
<li><p>Flexible and Scalable: Horizontal scaling provides virtually unlimited scalability by allowing you to add more servers or nodes to the cluster as your application's workload grows.</p>
</li>
</ol>
<p><strong>Disadvantages of Horizontal Scaling:</strong></p>
<ol>
<li><p>Complexity in Debugging: As the number of nodes increases, debugging and understanding code issues can become more complex, requiring effective monitoring and debugging tools.</p>
</li>
<li><p>Licensing Costs: Adding more nodes to the cluster may require additional licenses, leading to increased licensing costs for proprietary software.</p>
</li>
<li><p>Increased Data Center Costs: Horizontal scaling necessitates more physical space, power, and cooling requirements in data centers, resulting in higher operational costs.</p>
</li>
</ol>
<h3 id="heading-when-to-use-horizontal-scaling">When to Use Horizontal Scaling:</h3>
<p>Horizontal scaling is well-suited for applications that experience high traffic and require the ability to handle a large number of concurrent users. It provides excellent scalability, fault tolerance, and load balancing capabilities. If your application demands scalability beyond the capacity of a single server, horizontal scaling is a viable option.</p>
<h3 id="heading-vertical-scaling-scale-up">Vertical Scaling (Scale-Up):</h3>
<p>Vertical scaling, also known as scale-up, involves increasing the capacity of an individual server by adding more resources such as memory, storage, or processing power. In this approach, the focus is on enhancing the capabilities of a single machine rather than distributing the workload across multiple servers.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1688043799043/4155d3f0-c1a5-4284-a258-b02344152154.png" alt class="image--center mx-auto" /></p>
<p><strong>Advantages of Vertical Scaling:</strong></p>
<ol>
<li><p><strong>Cost-Effective Data Center:</strong> Vertical scaling can lead to cost savings in terms of data center space, cooling, and power requirements, as it involves a smaller hardware footprint compared to horizontal scaling.</p>
</li>
<li><p><strong>Ease of Management:</strong> Managing and maintaining a single server is generally easier than managing multiple servers in a distributed system.</p>
</li>
<li><p><strong>Flexible Resource Allocation:</strong> Vertical scaling allows for flexible allocation of resources to meet the specific needs of your application, such as increasing memory or CPU power.</p>
</li>
</ol>
<p><strong>Disadvantages of Vertical Scaling:</strong></p>
<ol>
<li><p><strong>Licensing Costs:</strong> Upgrading the resources of a single server often involves purchasing licenses for higher-end hardware components or proprietary software.</p>
</li>
<li><p><strong>Hardware Limitations:</strong> There is a limit to how much a single server can be upgraded, and eventually, you may reach the hardware's maximum capacity.</p>
</li>
<li><p><strong>Vendor Lock-In:</strong> Vertical scaling may tie you to a specific database vendor, making migration or switching to a different solution more challenging.</p>
</li>
</ol>
<h3 id="heading-when-to-use-vertical-scaling">When to Use Vertical Scaling:</h3>
<p>Vertical scaling is typically suitable for applications that require high data consistency or have unique data requirements. It is also an effective solution when you have a smaller user base and do not anticipate rapid or exponential growth in traffic.</p>
<h3 id="heading-differences-between-vertical-and-horizontal-scaling">Differences Between Vertical and Horizontal Scaling:</h3>
<div class="hn-table">
<table>
<thead>
<tr>
<td></td><td>Vertical Scaling</td><td>Horizontal Scaling</td></tr>
</thead>
<tbody>
<tr>
<td><strong>License Costs</strong></td><td>Lower</td><td>Higher</td></tr>
<tr>
<td><strong>Server Power</strong></td><td>Increases capacity of a single server</td><td>Increases overall server power</td></tr>
<tr>
<td><strong>Data Distribution</strong></td><td>Data present on a single node</td><td>Data partitioned across multiple nodes</td></tr>
<tr>
<td><strong>Hardware Limitations</strong></td><td>Limited by the capacity of a single server</td><td>Virtually limitless scalability</td></tr>
</tbody>
</table>
</div><h3 id="heading-choosing-the-right-scaling-method-for-your-application">Choosing the Right Scaling Method for Your Application:</h3>
<p>When deciding between vertical and horizontal scaling, consider the following factors:</p>
<ol>
<li><p><strong>Load Balancing:</strong> Horizontal scaling provides built-in load balancing by distributing the workload across multiple servers, while vertical scaling relies on a single server and does not require load balancing.</p>
</li>
<li><p><strong>Point of Failure:</strong> Horizontal scaling offers resilience by eliminating a single point of failure, whereas vertical scaling is susceptible to downtime if the single server fails.</p>
</li>
<li><p><strong>Speed:</strong> Vertical scaling is generally faster due to interprocess communication within a single server, while horizontal scaling may introduce latency due to network communication between multiple servers.</p>
</li>
<li><p><strong>Data Consistency:</strong> Vertical scaling is preferred for maintaining data consistency, whereas horizontal scaling with distributed data can introduce complexities in achieving consistent data across multiple nodes.</p>
</li>
<li><p><strong>Hardware Limitations:</strong> Consider the hardware limitations of vertical scaling, and if substantial growth beyond the capacity of a single server is expected, horizontal scaling may be a better option.</p>
</li>
</ol>
<p>In conclusion, data scalability is essential for optimal performance and flexibility in your database. Understand vertical and horizontal scaling differences to make informed decisions based on your application's needs. Consider load balancing, fault tolerance, speed, data consistency, and growth. Combine vertical and horizontal scaling for desired scalability and performance.</p>
]]></content:encoded></item><item><title><![CDATA[Iterators]]></title><description><![CDATA[In Python, an iterator is an object that enables traversal over a collection of items, one at a time.

It follows the iterator protocol, which involves implementing the __iter__() and __next__() methods.

The __iter__() method returns the iterator ob...]]></description><link>https://bitsnotion.com/iterators</link><guid isPermaLink="true">https://bitsnotion.com/iterators</guid><category><![CDATA[Python]]></category><category><![CDATA[Python 3]]></category><category><![CDATA[iterator]]></category><category><![CDATA[itertools]]></category><dc:creator><![CDATA[Nirmal Pandey]]></dc:creator><pubDate>Mon, 29 May 2023 05:54:08 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1687781370748/f15f51da-3d92-465a-9406-9b241a29af73.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<ul>
<li><p>In Python, an iterator is an object that enables traversal over a collection of items, one at a time.</p>
</li>
<li><p>It follows the iterator protocol, which involves implementing the <code>__iter__()</code> and <code>__next__()</code> methods.</p>
</li>
<li><p>The <code>__iter__()</code> method returns the iterator object itself, while <code>__next__()</code> retrieves the next element from the collection.</p>
</li>
<li><p>When there are no more elements, a <code>StopIteration</code> exception is raised.</p>
</li>
</ul>
<h3 id="heading-iterating-over-lists">Iterating over lists</h3>
<p><strong>Approach -1: Iterating over the list directly</strong></p>
<pre><code class="lang-python">list = [<span class="hljs-number">2</span>, <span class="hljs-number">4</span>, <span class="hljs-number">6</span>, <span class="hljs-number">8</span>, <span class="hljs-number">10</span>]
<span class="hljs-keyword">for</span> value <span class="hljs-keyword">in</span> list:
    print(value, end=<span class="hljs-string">' '</span>)
<span class="hljs-comment">#Output = 2 4 6 8 10</span>
</code></pre>
<ul>
<li><p>In this approach, the entire list <code>[2, 4, 6, 8, 10]</code> is stored in memory.</p>
</li>
<li><p>The <code>for</code> loop iterates over each element of the list, processing them one by one.</p>
</li>
<li><p>Memory usage is relatively higher since the complete list is stored in memory throughout the loop execution.</p>
</li>
</ul>
<p><strong>Approach -2:</strong> <strong>Using an iterator object</strong></p>
<pre><code class="lang-python">list = [<span class="hljs-number">2</span>, <span class="hljs-number">4</span>, <span class="hljs-number">6</span>, <span class="hljs-number">8</span>, <span class="hljs-number">10</span>]
iter_obj = iter(list) <span class="hljs-comment"># &lt;list_iterator object at 0x7fcf3519f670&gt;</span>
print(next(iter_obj)) <span class="hljs-comment"># Output = 2</span>
print(next(iter_obj))<span class="hljs-comment"># Output = 4</span>
print(next(iter_obj))<span class="hljs-comment"># Output = 6</span>
print(next(iter_obj))<span class="hljs-comment"># Output = 8</span>
print(next(iter_obj))<span class="hljs-comment"># Output = 10</span>
</code></pre>
<ul>
<li><p>In this approach, an iterator object is explicitly created using <code>iter(list)</code>.</p>
</li>
<li><p>Each call to <code>next(iter_obj)</code> retrieves the next element from the iterator, without storing the entire list in memory.</p>
</li>
<li><p>Only one element at a time is accessed and processed, reducing memory usage.</p>
</li>
<li><p>As elements are fetched one by one, the memory footprint is lower compared to</p>
</li>
</ul>
<h3 id="heading-built-in-iterators-in-python">Built-in Iterators in Python</h3>
<p>Python provides several built-in iterators and iterable objects that simplify common iteration tasks. Let's explore a few of them:</p>
<ol>
<li><p><strong>range()</strong></p>
<p> The <code>range()</code> function generates a sequence of numbers within a specified range. It can be used directly as an iterator.</p>
<pre><code class="lang-python"> <span class="hljs-keyword">for</span> i <span class="hljs-keyword">in</span> range(<span class="hljs-number">5</span>):
     print(i,end = <span class="hljs-string">" "</span>)
 <span class="hljs-comment">#Output = 0 1 2 3 4 5</span>
</code></pre>
</li>
<li><p><strong>enumerate()</strong></p>
<p> The <code>enumerate()</code> function is useful when we need both the index and value of each element while iterating over a sequence.</p>
<pre><code class="lang-python"> my_list = [<span class="hljs-string">'Nirmal'</span>, <span class="hljs-string">'Niraj'</span>, <span class="hljs-string">'Retrica'</span>]
 <span class="hljs-keyword">for</span> index, value <span class="hljs-keyword">in</span> enumerate(my_list):
     print(<span class="hljs-string">f"Index: <span class="hljs-subst">{index}</span>, Value: <span class="hljs-subst">{value}</span>"</span>)
</code></pre>
<p> <strong>Output :</strong></p>
<pre><code class="lang-python"> Index: <span class="hljs-number">0</span>, Value: nirmal
 Index: <span class="hljs-number">1</span>, Value: niraj
 Index: <span class="hljs-number">2</span>, Value: retrica
</code></pre>
</li>
<li><p><code>zip()</code>:</p>
<p> The <code>zip()</code> function combines multiple iterables into a single iterator. It pairs up corresponding elements from each iterable.</p>
<pre><code class="lang-python"> names =  [<span class="hljs-string">'Nirmal'</span>, <span class="hljs-string">'Niraj'</span>, <span class="hljs-string">'Retrica'</span>]
 ages = [<span class="hljs-number">23</span>, <span class="hljs-number">20</span>, <span class="hljs-number">27</span>]

 <span class="hljs-keyword">for</span> name, age <span class="hljs-keyword">in</span> zip(names, ages):
     print(<span class="hljs-string">f"Name: <span class="hljs-subst">{name}</span>, Age: <span class="hljs-subst">{age}</span>"</span>)
</code></pre>
<p> <strong>Output :</strong></p>
<pre><code class="lang-python"> Name: Nirmal, Age: <span class="hljs-number">23</span>
 Name: Niraj, Age: <span class="hljs-number">20</span>
 Name: Retrica, Age: <span class="hljs-number">27</span>
</code></pre>
</li>
</ol>
<h3 id="heading-itertools-module">Itertools Module</h3>
<p>The <code>itertools</code> module is a powerful tool that provides various functions for efficient iteration and a combination of iterables. It extends the capabilities of built-in iterators.</p>
<p><strong>Some modules are :</strong></p>
<p>1. <code>itertools.cycle()</code></p>
<p>This creates an iterator that cycles through elements of an iterable indefinitely.</p>
<pre><code class="lang-python"><span class="hljs-keyword">import</span> itertools

name = [<span class="hljs-string">"nirmal"</span>, <span class="hljs-string">"niraj"</span>, <span class="hljs-string">"retrica"</span>]
myloopy = itertools.cycle(name)

print(next(myloopy))  <span class="hljs-comment"># Output: nirmal</span>
print(next(myloopy))  <span class="hljs-comment"># Output: niraj</span>
print(next(myloopy))  <span class="hljs-comment"># Output: retrica</span>
</code></pre>
<p>2. <code>itertools.chain()</code></p>
<p>This combines multiple iterables into a single sequence.</p>
<pre><code class="lang-python"><span class="hljs-keyword">import</span> itertools

inter1 = itertools.chain(<span class="hljs-string">"nirmal"</span>, <span class="hljs-string">"pandey"</span>)
print(list(inter1))  <span class="hljs-comment"># Output: ['n', 'i', 'r', 'm', 'a', 'l', 'p', 'a', 'n', 'd', 'e', 'y']</span>
</code></pre>
<ol>
<li><code>itertools. accumulate()</code></li>
</ol>
<p>This returns an iterator that produces accumulated sums of an iterable.</p>
<pre><code class="lang-python"><span class="hljs-keyword">import</span> itertools

num = [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>, <span class="hljs-number">6</span>]
inter2 = itertools.accumulate(num)
print(list(inter2))  <span class="hljs-comment"># Output: [1, 3, 6, 10, 15, 21]</span>
</code></pre>
<p>4.<code>itertools.repeat()</code></p>
<p>This generates an iterator that repeats a value a specified number of times.</p>
<pre><code class="lang-python"><span class="hljs-keyword">import</span> itertools

inter3 = itertools.repeat(<span class="hljs-number">10</span>, <span class="hljs-number">3</span>)
print(list(inter3))  <span class="hljs-comment"># Output: [10, 10, 10]</span>
</code></pre>
<p>5: <code>itertools.compress()</code></p>
<p>This filters an iterable based on the truth value of corresponding selectors.</p>
<pre><code class="lang-python"><span class="hljs-keyword">import</span> itertools

inter4 = itertools.compress(<span class="hljs-string">"nirmal"</span>, [<span class="hljs-number">1</span>, <span class="hljs-number">0</span>, <span class="hljs-number">1</span>, <span class="hljs-number">0</span>, <span class="hljs-number">1</span>, <span class="hljs-number">1</span>])
print(list(inter4))  <span class="hljs-comment"># Output: ['n', 'r', 'a', 'l']</span>
</code></pre>
<h3 id="heading-custom-iterator"><strong>Custom Iterator</strong></h3>
<pre><code class="lang-python"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MyIterator</span>:</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__init__</span>(<span class="hljs-params">self, data</span>):</span>
        self.data = data
        self.index = <span class="hljs-number">0</span>

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__iter__</span>(<span class="hljs-params">self</span>):</span>
        <span class="hljs-keyword">return</span> self

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__next__</span>(<span class="hljs-params">self</span>):</span>
        <span class="hljs-keyword">if</span> self.index &gt;= len(self.data):
            <span class="hljs-keyword">raise</span> StopIteration
        value = self.data[self.index]
        self.index += <span class="hljs-number">1</span>
        <span class="hljs-keyword">return</span> value


my_list = [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>]
my_iter = MyIterator(my_list)

<span class="hljs-keyword">for</span> item <span class="hljs-keyword">in</span> my_iter:
    print(item)
</code></pre>
<p>In this example, we create a custom iterator <code>MyIterator</code> takes a list as input. The <code>__iter__()</code> method returns the iterator object itself, and <code>__next__()</code> fetches the next element from the list. Once there are no more elements, a <code>StopIteration</code> exception is raised.</p>
]]></content:encoded></item><item><title><![CDATA[Encapsulation]]></title><description><![CDATA[Encapsulation is an essential concept in object-oriented programming that promotes data hiding and helps maintain code integrity.

In Python, although there are no strict access modifiers like in some other languages, developers can use naming conven...]]></description><link>https://bitsnotion.com/encapsulation</link><guid isPermaLink="true">https://bitsnotion.com/encapsulation</guid><category><![CDATA[Python]]></category><category><![CDATA[Python 3]]></category><category><![CDATA[encapsulation]]></category><category><![CDATA[protected member]]></category><category><![CDATA[private member]]></category><dc:creator><![CDATA[Nirmal Pandey]]></dc:creator><pubDate>Mon, 22 May 2023 12:22:27 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1687705443067/d3624efc-cdfc-44c4-930c-9e38a54d98b1.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<ul>
<li><p>Encapsulation is an essential concept in object-oriented programming that promotes data hiding and helps maintain code integrity.</p>
</li>
<li><p>In Python, although there are no strict access modifiers like in some other languages, developers can use naming conventions to indicate the intended visibility of class members.</p>
</li>
</ul>
<h3 id="heading-private-members">Private Members</h3>
<ul>
<li><p>Private members in Python are denoted by a double underscore (<code>__</code>) prefix before the variable or method name.</p>
</li>
<li><p>By convention, this prefix indicates that the member is intended for internal use within the class and should not be accessed directly from outside.</p>
</li>
</ul>
<p><strong>Example:</strong></p>
<pre><code class="lang-python"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MyClass</span>:</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__init__</span>(<span class="hljs-params">self</span>):</span>
        self.__private_var = <span class="hljs-number">100</span>

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__private_method</span>(<span class="hljs-params">self</span>):</span>
        print(<span class="hljs-string">"This is a private method."</span>)

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">public_method</span>(<span class="hljs-params">self</span>):</span>
        self.__private_method()
        print(<span class="hljs-string">f"The private variable value is: <span class="hljs-subst">{self.__private_var}</span>"</span>)


obj = MyClass()
obj.public_method()
</code></pre>
<pre><code class="lang-python">This <span class="hljs-keyword">is</span> a private method.
The private variable value <span class="hljs-keyword">is</span>: <span class="hljs-number">100</span>
</code></pre>
<p>In the above example, <code>__private_var</code> and <code>__private_method</code> are private members of the <code>MyClass</code> class. They are accessed within the class using the double underscore prefix. If we want to access the private variable from outside like <code>obj.__private_method()</code> then it shows <strong>AttributeError</strong></p>
<h3 id="heading-protected-members">Protected Members</h3>
<ul>
<li><p>Protected members in Python are denoted by a single underscore (<code>_</code>) prefix before the variable or method name.</p>
</li>
<li><p>By convention, this prefix suggests that the member is intended to be used within the class and its subclasses.</p>
</li>
<li><p>Though protected members can still be accessed from outside the class, developers should treat them as non-public, discouraging direct access.</p>
</li>
</ul>
<p><strong>Example:</strong></p>
<pre><code class="lang-python"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">BaseClass</span>:</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__init__</span>(<span class="hljs-params">self</span>):</span>
        self._protected_var = <span class="hljs-number">10</span>

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">_protected_method</span>(<span class="hljs-params">self</span>):</span>
        print(<span class="hljs-string">"This is a protected method."</span>)

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">SubClass</span>(<span class="hljs-params">BaseClass</span>):</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">access_protected</span>(<span class="hljs-params">self</span>):</span>
        print(<span class="hljs-string">f"The protected variable value is: <span class="hljs-subst">{self._protected_var}</span>"</span>)
        self._protected_method()


obj = SubClass()
obj.access_protected()
</code></pre>
<p>In this example, <code>_protected_var</code> and <code>_protected_method</code> are protected members within the <code>BaseClass</code>. They are accessible within the <strong>class</strong> and its <strong>subclasses</strong>.</p>
]]></content:encoded></item><item><title><![CDATA[Abstraction]]></title><description><![CDATA[Abstraction allows you to create abstract classes and methods to represent common characteristics and behaviors of a group of related objects.

It focuses on hiding the internal implementation details of a class and providing a simplified interface f...]]></description><link>https://bitsnotion.com/abstraction</link><guid isPermaLink="true">https://bitsnotion.com/abstraction</guid><category><![CDATA[Python]]></category><category><![CDATA[Python 3]]></category><category><![CDATA[abstraction]]></category><category><![CDATA[abstractmethod]]></category><category><![CDATA[abstractclass]]></category><dc:creator><![CDATA[Nirmal Pandey]]></dc:creator><pubDate>Mon, 15 May 2023 12:20:39 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1687705097864/d2269143-9ebc-48cc-9bbf-56c3de477549.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<ul>
<li><p>Abstraction allows you to create abstract classes and methods to represent common characteristics and behaviors of a group of related objects.</p>
</li>
<li><p>It focuses on hiding the internal implementation details of a class and providing a simplified interface for interacting with objects.</p>
</li>
<li><p>In Python, abstraction is achieved through abstract classes and methods using the <code>abc</code> module, which stands for "Abstract Base Classes".</p>
</li>
</ul>
<h3 id="heading-abstract-classes">Abstract Classes</h3>
<ul>
<li><p>An abstract class is a class that cannot be instantiated and acts as a <strong>blueprint</strong> for creating subclasses.</p>
</li>
<li><p>It is a common interface or application programming interface(API) for concrete subclass.</p>
</li>
</ul>
<pre><code class="lang-python"><span class="hljs-keyword">from</span> abc <span class="hljs-keyword">import</span> ABC, abstractmethod

<span class="hljs-comment">#Abstract class</span>
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Shape</span>(<span class="hljs-params">ABC</span>):</span>
<span class="hljs-meta">    @abstractmethod</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">area</span>(<span class="hljs-params">self</span>):</span>
        <span class="hljs-keyword">pass</span>

obj = Shape()
obj.area()
</code></pre>
<p><strong>Output</strong></p>
<pre><code class="lang-python">TypeError: Can<span class="hljs-string">'t instantiate abstract class pen with abstract method area</span>
</code></pre>
<p>In this example, <code>Shape</code> is an abstract class that defines an abstract method<code>area()</code>. The <code>abstractmethod</code> decorator indicates that these methods must be implemented in the child subclasses derived from the <code>Shape</code> class. Attempting to create an instance of the <code>Shape</code> class directly will result in a <code>TypeError</code>.</p>
<pre><code class="lang-python"><span class="hljs-keyword">from</span> abc <span class="hljs-keyword">import</span> ABC, abstractmethod

<span class="hljs-comment">#Abstract class</span>
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Shape</span>(<span class="hljs-params">ABC</span>):</span>
<span class="hljs-meta">    @abstractmethod</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">area</span>(<span class="hljs-params">self</span>):</span>
        <span class="hljs-keyword">pass</span>

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Circle</span>(<span class="hljs-params">Shape</span>):</span>
    <span class="hljs-keyword">pass</span>

obj = Circle()
</code></pre>
<p><strong>Output</strong></p>
<pre><code class="lang-python">TypeError: Can<span class="hljs-string">'t instantiate abstract class pen with abstract method area</span>
</code></pre>
<p>If I implement the <strong>radius()</strong> method in the child class then it executes with error-free</p>
<pre><code class="lang-python">
<span class="hljs-keyword">from</span> abc <span class="hljs-keyword">import</span> ABC, abstractmethod

<span class="hljs-comment">#Abstract class</span>
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Shape</span>(<span class="hljs-params">ABC</span>):</span>
<span class="hljs-meta">    @abstractmethod</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">area</span>(<span class="hljs-params">self</span>):</span>
        <span class="hljs-keyword">pass</span>

<span class="hljs-string">'''
Circle class inherit abstract class Shape ,so it is mandatory to use 
method of parent/abstract class in this child class
'''</span>
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Circle</span>(<span class="hljs-params">Shape</span>):</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__init__</span>(<span class="hljs-params">self, radius</span>):</span>
        self.radius = radius

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">area</span>(<span class="hljs-params">self</span>):</span>
        <span class="hljs-keyword">return</span> <span class="hljs-number">3.14</span> * self.radius**<span class="hljs-number">2</span>


obj = Circle(<span class="hljs-number">2</span>)
area = obj.area()
print(<span class="hljs-string">f"Area is : <span class="hljs-subst">{area}</span>"</span>)
</code></pre>
<p><strong>Output :</strong></p>
<pre><code class="lang-python">Area <span class="hljs-keyword">is</span> : <span class="hljs-number">12.56</span>
</code></pre>
<p>In this example, the <code>Circle</code> class is a subclass of the <code>Shape</code> abstract class. It provides implementations for the <code>area()</code> and <code>perimeter()</code> methods, which are required by the <code>Shape</code> abstract class. The <code>Circle</code> class can be instantiated, and its methods can be called to perform specific calculations related to circles.</p>
]]></content:encoded></item><item><title><![CDATA[Polymorphism]]></title><description><![CDATA[Polymorphism is a fundamental concept in object-oriented programming that allows objects of different classes to be treated as objects of a common superclass.
Method Overriding

Method overriding occurs when a subclass defines a method with the same ...]]></description><link>https://bitsnotion.com/polymorphism</link><guid isPermaLink="true">https://bitsnotion.com/polymorphism</guid><category><![CDATA[Python]]></category><category><![CDATA[Python 3]]></category><category><![CDATA[METHOD OVERRIDING]]></category><category><![CDATA[polymorphism]]></category><category><![CDATA[method OVERLOADING]]></category><dc:creator><![CDATA[Nirmal Pandey]]></dc:creator><pubDate>Tue, 09 May 2023 12:18:12 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1687702262354/42446bc2-f398-4f19-9254-38183c5c26d0.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Polymorphism is a fundamental concept in object-oriented programming that allows objects of different classes to be treated as objects of a common superclass.</p>
<h3 id="heading-method-overriding">Method Overriding</h3>
<ul>
<li><p>Method overriding occurs when a subclass defines a method with the same name as a method in its superclass.</p>
</li>
<li><p>The method in the subclass overrides the implementation of the method in the superclass.</p>
</li>
<li><p>This allows for different implementations of the same method across different classes.</p>
</li>
</ul>
<p>Here's an example of method overriding in Python:</p>
<pre><code class="lang-python"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Animal</span>:</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">sound</span>(<span class="hljs-params">self</span>):</span>
        print(<span class="hljs-string">"Animal makes a sound"</span>)

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Dog</span>(<span class="hljs-params">Animal</span>):</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">sound</span>(<span class="hljs-params">self</span>):</span>
        print(<span class="hljs-string">"Dog barks"</span>)


<span class="hljs-comment"># Creating instances of different classes</span>
animal = Animal()
dog = Dog()

<span class="hljs-comment"># Calling the overridden method</span>
animal.sound()  <span class="hljs-comment"># Output: Animal makes a sound</span>
dog.sound()     <span class="hljs-comment"># Output: Dog barks</span>
</code></pre>
<p>In the example above, the <code>Animal</code> class has a method <code>make_sound()</code>. The <code>Dog</code> class inherit from the <code>Animal</code> class and override the <code>make_sound()</code> method with their specific implementations. When <code>make_sound()</code> is called on an instance of each class, the overridden method in the respective subclass is invoked.</p>
<h3 id="heading-method-overloading">Method Overloading</h3>
<ul>
<li><p>Method overloading refers to defining multiple methods with the same name but different parameters within a class.</p>
</li>
<li><p>Python doesn't support method overloading in the same way as some other languages (e.g., Java), where methods can have different signatures.</p>
</li>
<li><p>However, you can achieve a form of method overloading using default argument values or variable-length arguments.</p>
</li>
</ul>
<p>Here's an example demonstrating method overloading using default argument values:</p>
<pre><code class="lang-python"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Calculator</span>:</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">add</span>(<span class="hljs-params">self, a, b</span>):</span>
        <span class="hljs-keyword">return</span> a + b

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">add</span>(<span class="hljs-params">self, a, b, c</span>):</span>
        <span class="hljs-keyword">return</span> a + b + c

<span class="hljs-comment"># Creating an instance of the Calculator class</span>
calculator = Calculator()

<span class="hljs-comment"># Calling the overloaded methods</span>
result1 = calculator.add(<span class="hljs-number">2</span>, <span class="hljs-number">3</span>)
result2 = calculator.add(<span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>)

print(result1)  <span class="hljs-comment"># Output: 5</span>
print(result2)  <span class="hljs-comment"># Output: 9</span>
</code></pre>
<p>In this example, the <code>Calculator</code> class has two <code>add()</code> methods with different parameter counts. By providing different parameter lists, we can achieve a form of method overloading.</p>
]]></content:encoded></item><item><title><![CDATA[Inheritance in Python]]></title><description><![CDATA[Inheritance is a fundamental concept in object-oriented programming that allows you to create new classes based on existing classes, enabling code reuse and promoting a hierarchical structure.
Single Inheritance:

Single inheritance refers to a scena...]]></description><link>https://bitsnotion.com/inheritance-in-python</link><guid isPermaLink="true">https://bitsnotion.com/inheritance-in-python</guid><category><![CDATA[Python 3]]></category><category><![CDATA[inheritance]]></category><category><![CDATA[mro algorithm]]></category><dc:creator><![CDATA[Nirmal Pandey]]></dc:creator><pubDate>Wed, 03 May 2023 12:17:03 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1687694960485/8579b5ca-0010-432c-85bc-7bfe20f3c7ae.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Inheritance is a fundamental concept in object-oriented programming that allows you to create new classes based on existing classes, enabling code reuse and promoting a hierarchical structure.</p>
<h3 id="heading-single-inheritance">Single Inheritance:</h3>
<ul>
<li><p>Single inheritance refers to a scenario where a class inherits from a single base class.</p>
</li>
<li><p>The derived class acquires the attributes and methods of the base class, allowing for code reuse and extension of functionality.</p>
</li>
</ul>
<pre><code class="lang-python"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Creatures</span>:</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">character</span>(<span class="hljs-params">self</span>):</span>
        print(<span class="hljs-string">"They Cannot talk"</span>)

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Bird</span>(<span class="hljs-params">Creatures</span>):</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">feature</span>(<span class="hljs-params">self</span>):</span>
        print(<span class="hljs-string">"Bird Can Fly"</span>)

<span class="hljs-comment"># Creating an instance of Dog</span>
bird = Bird()
bird.feature()  <span class="hljs-comment"># Output: Bird Fly</span>
bird.character() <span class="hljs-comment"># Output: They Cannot talk</span>
</code></pre>
<p>In this example, the <code>Bird</code> class inherits from the <code>Creatures</code> class using single inheritance. So, I can easily use the properties of the Creatures class inside the <strong>Bird</strong> class. For instance, <code>bird. character()</code> in the above example.</p>
<h3 id="heading-multilevel-inheritance">Multilevel Inheritance</h3>
<p>Multilevel inheritance involves a chain of inheritance where a derived class inherits from a base class, and another class inherits from the derived class.</p>
<pre><code class="lang-python"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Vehicle</span>:</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">drive</span>(<span class="hljs-params">self</span>):</span>
        print(<span class="hljs-string">"Help in Driving"</span>)

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Car</span>(<span class="hljs-params">Vehicle</span>):</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__init__</span>(<span class="hljs-params">self, color, speed</span>):</span>
        self.color = color
        self.speed = speed

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">feature</span>(<span class="hljs-params">self</span>):</span>
        print(<span class="hljs-string">f"Its color is <span class="hljs-subst">{self.color}</span> and speed is<span class="hljs-subst">{self.speed}</span>"</span>)

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">SportsCar</span>(<span class="hljs-params">Car</span>):</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__init__</span>(<span class="hljs-params">self, color, speed, price</span>):</span>
        super().__init__(color, speed)<span class="hljs-comment"># overriding init method of Car</span>
        self.price = price


car = Car(<span class="hljs-string">'black'</span>,<span class="hljs-string">'100km/hr'</span>)
sport_car = SportsCar(<span class="hljs-string">'red'</span>,<span class="hljs-string">'200km/hr'</span>,<span class="hljs-string">'15000$'</span>)

car.drive()
sport_car.feature() <span class="hljs-comment"># accessing Car method</span>
sport_car.drive() <span class="hljs-comment">#accessing Vehicle method</span>
</code></pre>
<p><strong>Output :</strong></p>
<pre><code class="lang-python">Help <span class="hljs-keyword">in</span> Driving
Its color <span class="hljs-keyword">is</span> red <span class="hljs-keyword">and</span> speed is200km/hr
Help <span class="hljs-keyword">in</span> Driving
</code></pre>
<p>In this example, the <code>SportsCar</code> class inherits from the<code>Car</code> class, which itself inherits from the <code>Vehicle</code> class. The <code>SportsCar</code> class inherits the <code>drive</code> method from the <code>Vehicle</code> class through the intermediate <code>Car</code> class.</p>
<h3 id="heading-super-keyword">super() keyword</h3>
<ul>
<li><p><code>super()</code> is a built-in function that allows you to call a method from a parent class within a subclass.</p>
</li>
<li><p>It provides a convenient way to invoke the parent class's methods and access its attributes.</p>
</li>
<li><p>In the above example of multilevel inheritance, I am using <strong>super().__init__(color, speed)</strong> in the class <strong>SportsCar</strong> to override attributes from <strong>Car</strong> class.</p>
<pre><code class="lang-python">  <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">SportsCar</span>(<span class="hljs-params">Car</span>):</span>
      <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__init__</span>(<span class="hljs-params">self, color, speed, price</span>):</span>
          super().__init__(color, speed)<span class="hljs-comment">#overriding init method of Car</span>
          self.price = price

  <span class="hljs-string">'''THIS CODE IS EQUIVALENT TO BELOW CODE'''</span>

  <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">SportsCar</span>(<span class="hljs-params">Car</span>):</span>
      <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__init__</span>(<span class="hljs-params">self, color, speed, price</span>):</span>
          self.color = color
          self.speed = speed
          self.price = price
</code></pre>
</li>
</ul>
<h3 id="heading-multiple-inheritance">Multiple Inheritance</h3>
<ul>
<li><p>Multiple inheritance allows a class to inherit from more than one base class.</p>
</li>
<li><p>The derived class inherits attributes and methods from all the base classes, enabling it to combine the properties and behaviors of multiple classes. Let's explore an example:</p>
</li>
</ul>
<pre><code class="lang-python"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Vehicle</span>:</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">drive</span>(<span class="hljs-params">self</span>):</span>
        print(<span class="hljs-string">"Driving"</span>)

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Car</span>:</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__init__</span>(<span class="hljs-params">self, color, speed</span>):</span>
        self.color = color
        self.speed = speed

    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">feature</span>(<span class="hljs-params">self</span>):</span>
        print(<span class="hljs-string">f"It color is <span class="hljs-subst">{self.color}</span> and speed is<span class="hljs-subst">{self.speed}</span>"</span>)

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">SportsCar</span>(<span class="hljs-params">Vehicle, Car</span>):</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__init__</span>(<span class="hljs-params">self, color, speed, price</span>):</span>
        super().__init__(color, speed)<span class="hljs-comment">#overriding attribute of Car class</span>
        self.price = price


car = Car(<span class="hljs-string">'black'</span>,<span class="hljs-string">'100km/hr'</span>)
sport_car = SportsCar(<span class="hljs-string">'red'</span>,<span class="hljs-string">'200km/hr'</span>,<span class="hljs-string">'15000$'</span>)
sport_car.drive()  <span class="hljs-comment"># Output: Driving</span>
</code></pre>
<p>In this example, the <code>Duck</code> class inherits from both the <code>Flyer</code> and <code>Swimmer</code> classes using multiple inheritances. The <code>Duck</code> class can access the methods of both base classes.</p>
<h3 id="heading-mro-algorithm">MRO algorithm</h3>
<ul>
<li><p>MRO (Method Resolution Order) is a process in Python that determines the order in which methods are resolved or searched for in a class hierarchy.</p>
</li>
<li><p>It is used when multiple inheritance is involved, and it helps avoid ambiguities and conflicts in method resolution.</p>
<pre><code class="lang-python">  <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">A</span>:</span>
      <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">greet</span>(<span class="hljs-params">self</span>):</span>
          print(<span class="hljs-string">"Hello from A"</span>)

  <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">B</span>(<span class="hljs-params">A</span>):</span>
      <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">greet</span>(<span class="hljs-params">self</span>):</span>
          print(<span class="hljs-string">"Hello from B"</span>)

  <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">C</span>(<span class="hljs-params">A</span>):</span>
      <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">greet</span>(<span class="hljs-params">self</span>):</span>
          print(<span class="hljs-string">"Hello from C"</span>)

  <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">D</span>(<span class="hljs-params">B, C</span>):</span>
      <span class="hljs-keyword">pass</span>

  <span class="hljs-comment"># Creating an instance of D</span>
  d = D()
  d.greet()
  print(d.greet())
  print(D.mro())
</code></pre>
<p>  <strong>Output :</strong></p>
<pre><code class="lang-python">  Hello <span class="hljs-keyword">from</span> B
  [&lt;<span class="hljs-class"><span class="hljs-keyword">class</span> '<span class="hljs-title">__main__</span>.<span class="hljs-title">D</span>'&gt;, &lt;<span class="hljs-title">class</span> '<span class="hljs-title">__main__</span>.<span class="hljs-title">B</span>'&gt;, &lt;<span class="hljs-title">class</span> '<span class="hljs-title">__main__</span>.<span class="hljs-title">C</span>'&gt;,
   &lt;<span class="hljs-title">class</span> '<span class="hljs-title">__main__</span>.<span class="hljs-title">A</span>'&gt;, &lt;<span class="hljs-title">class</span> '<span class="hljs-title">object</span>'&gt;]</span>
</code></pre>
</li>
<li><p>If we want to access the greet() method making an object for D then first it will check it in <strong>class D and</strong> then similarly in <strong>class B, C, and A</strong> respectively according to <code>mro</code> algorithm as in the above example.</p>
</li>
<li><p>We are sure that we are creating the object of class D.So, it first checks in class D. But between <strong>class B and class C, class B</strong> is on the left of <strong>class C</strong>. Therefore, it accesses the method from <strong>class B</strong> based on <code>mro()</code> algorithm.</p>
</li>
</ul>
]]></content:encoded></item><item><title><![CDATA[Methods and Its Types]]></title><description><![CDATA[In object-oriented programming, Python provides different types of methods to define the behavior of classes. Three commonly used methods are instance methods, class methods, and static methods. Such methods help us to create more organized and effic...]]></description><link>https://bitsnotion.com/methods-and-its-types</link><guid isPermaLink="true">https://bitsnotion.com/methods-and-its-types</guid><category><![CDATA[Python 3]]></category><category><![CDATA[static method]]></category><category><![CDATA[instance method]]></category><category><![CDATA[class method]]></category><dc:creator><![CDATA[Nirmal Pandey]]></dc:creator><pubDate>Thu, 27 Apr 2023 12:16:14 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1687684315434/5bfec3cc-adfe-4a24-aec7-d697821992e8.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In object-oriented programming, Python provides different types of methods to define the behavior of classes. Three commonly used methods are <strong>instance methods, class methods, and static methods</strong>. Such methods help us to create more organized and efficient code structures in Python.</p>
<h3 id="heading-instance-method">Instance Method</h3>
<ul>
<li><p>Instance methods are the most common type of method in Python classes.</p>
</li>
<li><p>They are associated with objects (instances) of a class and are defined <strong>within</strong> the class definition.</p>
</li>
<li><p>Instance methods take the <code>self</code> parameter, which represents the instance itself.</p>
</li>
<li><p>They can access and modify instance variables and invoke other instance methods of the same class. To define an instance method, we use the <code>def</code> keyword.</p>
</li>
</ul>
<pre><code class="lang-python"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Person</span>:</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">instance_method</span>(<span class="hljs-params">self, name, age</span>):</span>
        <span class="hljs-comment"># Access instance variables</span>
        self.name = name
        self.age = age

<span class="hljs-comment"># Creating an instance of MyClass</span>
obj = Person()

<span class="hljs-comment"># Calling the instance method</span>
obj.instance_method(<span class="hljs-string">"Nirmal"</span>,<span class="hljs-string">"23"</span>)

print(obj.name, obj.age)<span class="hljs-comment"># Output = Nirmal 23</span>
</code></pre>
<p>In the example above, <code>instance_method()</code> is an instance method that takes two arguments. It accesses the instance variables <code>arg1</code> and <code>arg2</code> using the <code>self</code> parameter performs some operations and modifies the instance variables accordingly.</p>
<h3 id="heading-class-method">Class Method</h3>
<ul>
<li><p>They can be called on the class itself to perform operations rather than instances.</p>
</li>
<li><p>Class methods take the <code>cls</code> parameter, which represents the class itself.</p>
</li>
<li><p>We use the <code>@classmethod</code> decorator to define a class method.</p>
</li>
<li><p>Class methods are often used for <strong>alternative constructors</strong>.</p>
</li>
</ul>
<pre><code class="lang-python"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MyClass</span>:</span>
    class_variable = <span class="hljs-string">"Hello, World!"</span>

<span class="hljs-meta">    @classmethod</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">class_method</span>(<span class="hljs-params">cls</span>):</span>
        print(<span class="hljs-string">"This is a class method."</span>)
        print(<span class="hljs-string">"Accessing class variable:"</span>, cls.class_variable)


<span class="hljs-comment"># Calling class method</span>
MyClass.class_method()
</code></pre>
<h3 id="heading-static-method">Static Method</h3>
<ul>
<li><p>If we have nothing to do with instance and class then we use static method.</p>
</li>
<li><p>They are defined within the class definition using the <code>@staticmethod</code> decorator.</p>
</li>
<li><p>Static methods are not bound to the instance or the class, making them independent and self-contained.</p>
</li>
</ul>
<pre><code class="lang-python"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">MyClass</span>:</span>

<span class="hljs-meta">    @staticmethod</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">static_method</span>():</span>
        print(<span class="hljs-string">"This is a static method."</span>)

<span class="hljs-comment"># Calling the static method</span>
MyClass.static_method()
</code></pre>
<p><strong>Output:</strong></p>
<pre><code class="lang-python">This <span class="hljs-keyword">is</span> a static method.
</code></pre>
]]></content:encoded></item><item><title><![CDATA[Object Oriented Programming]]></title><description><![CDATA[Python, a popular programming language, offers a powerful feature called object-oriented programming (OOP).

This approach allows developers to organize their code in a way that makes it easier to understand and reuse.

Central to OOP in Python are c...]]></description><link>https://bitsnotion.com/object-oriented-programming</link><guid isPermaLink="true">https://bitsnotion.com/object-oriented-programming</guid><category><![CDATA[Python 3]]></category><category><![CDATA[Python]]></category><category><![CDATA[Object Oriented Programming]]></category><category><![CDATA[classes]]></category><category><![CDATA[Objects]]></category><dc:creator><![CDATA[Nirmal Pandey]]></dc:creator><pubDate>Mon, 17 Apr 2023 12:15:12 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1687682990493/d5156523-54e6-4f11-a39e-937a4de9d5e1.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<ul>
<li><p>Python, a popular programming language, offers a powerful feature called object-oriented programming (OOP).</p>
</li>
<li><p>This approach allows developers to organize their code in a way that makes it easier to understand and reuse.</p>
</li>
<li><p>Central to OOP in Python are classes, which act as blueprints for creating objects with shared characteristics and behaviors.</p>
</li>
</ul>
<h3 id="heading-classes">Classes</h3>
<ul>
<li><p>They are abstract and blueprint only. For example, Let's imagine a map of your house before you construct it is <strong>class</strong>.</p>
</li>
<li><p>One class can have many objects like we can make multiple houses with the help of the same map.</p>
<pre><code class="lang-python">  <span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Classname</span>:</span>
      <span class="hljs-comment">#your variables and functions</span>
</code></pre>
</li>
</ul>
<h3 id="heading-objects">Objects</h3>
<ul>
<li><p>When the <strong>house</strong> is constructed from it then it is considered an object which exists and is real.</p>
</li>
<li><p>Similarly, various features of house such as <strong>color, furniture, number of rooms</strong>, etc are also objects.</p>
<pre><code class="lang-python">  object_name = Classname()
</code></pre>
</li>
</ul>
<h3 id="heading-some-examples-to-create-classes-and-objects"><strong>Some examples to create classes and objects :</strong></h3>
<pre><code class="lang-python"><span class="hljs-comment">#creating class</span>
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Number</span>:</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">sum</span>(<span class="hljs-params">self</span>):</span>
        <span class="hljs-keyword">return</span> self.a + self.b

obj = Number()
obj.a = <span class="hljs-number">10</span>
obj.b = <span class="hljs-number">10</span>
s = obj.sum()<span class="hljs-comment">#calling sum() with </span>
print(s) <span class="hljs-comment"># Object = 20</span>
</code></pre>
<h3 id="heading-creating-a-class-with-constructorinit"><strong>Creating a class with constructor(</strong><code>__init__())</code></h3>
<pre><code class="lang-python"><span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">Map</span>:</span>
    <span class="hljs-comment">#instance method because it is bound to instance of class</span>
    category = <span class="hljs-string">'house_category'</span>
    <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">__init__</span>(<span class="hljs-params">self, color, num_rooms, area</span>):</span>
        <span class="hljs-comment">#declaring instance variable</span>
        self.color = color
        self.num_rooms = num_rooms
        self.area = area

<span class="hljs-comment"># Creating different objects for the House class</span>
house1 = Map(<span class="hljs-string">"Green"</span>, <span class="hljs-number">10</span>, <span class="hljs-number">2500</span>)<span class="hljs-comment">#object1</span>
house2 = Map(<span class="hljs-string">"Orange"</span>, <span class="hljs-number">2</span>, <span class="hljs-number">1000</span>)<span class="hljs-comment">#object3</span>

print(house1.color) <span class="hljs-comment"># Output = Green</span>
print(house2.num_rooms) <span class="hljs-comment"># Output = 2</span>
</code></pre>
<h3 id="heading-init-constructor">__init__() constructor</h3>
<ul>
<li><p><code>__init__</code> method is the <strong>constructor</strong> in Python which is <strong>automatically called</strong> at the time of object creation.</p>
</li>
<li><p><code>__init__</code> is the <strong>instance method</strong> because it is bound to the instance of the class.</p>
</li>
<li><p>Various variable inside this method is <strong>instance variable</strong> because it is associated with the object(<code>self</code>)</p>
</li>
<li><p>category variable or attributes outside init consctuctor is class variable.</p>
</li>
</ul>
<h3 id="heading-self-keyword">Self keyword</h3>
<ul>
<li><p><code>self</code> parameter is automatically passed as the first argument whenever the method is called.</p>
</li>
<li><p>By convention, it is named <code>self</code>, although you can technically use any valid variable name in its place.</p>
</li>
<li><p><code>self</code> is the object in python.</p>
</li>
<li><p><code>self</code> parameter allows you to access and manipulate the instance's attributes and call other instance methods within the class. For instance, self.<strong>attribute_name</strong> or self.<strong>function_name</strong>()</p>
</li>
</ul>
]]></content:encoded></item><item><title><![CDATA[Errors and Exceptions]]></title><description><![CDATA[Errors and Exceptions in Python are mechanisms for handling issues that arise during program execution. Errors indicate code issues that prevent successful execution, while exceptions are events that disrupt the normal flow of code.
Error types
Synta...]]></description><link>https://bitsnotion.com/errors-and-exceptions</link><guid isPermaLink="true">https://bitsnotion.com/errors-and-exceptions</guid><category><![CDATA[Python]]></category><category><![CDATA[Python 3]]></category><category><![CDATA[exceptionhandling]]></category><category><![CDATA[exceptions]]></category><category><![CDATA[errors]]></category><dc:creator><![CDATA[Nirmal Pandey]]></dc:creator><pubDate>Sun, 09 Apr 2023 12:14:35 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1687507943750/cafe67cd-806a-4815-be89-1431f9e47e51.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Errors and Exceptions in Python are mechanisms for handling issues that arise during program execution. Errors indicate code issues that prevent successful execution, while exceptions are events that disrupt the normal flow of code.</p>
<h2 id="heading-error-types">Error types</h2>
<h3 id="heading-syntax-error">Syntax error</h3>
<p>Errors where the code is not valid in Python.</p>
<pre><code class="lang-python">a, b = <span class="hljs-number">1</span>, <span class="hljs-number">2</span>
<span class="hljs-keyword">if</span> a &lt; b
    print(<span class="hljs-string">"Messge"</span>)
</code></pre>
<p><strong>Output :</strong></p>
<pre><code class="lang-python">File <span class="hljs-string">"main.py"</span>, line <span class="hljs-number">2</span>
    <span class="hljs-keyword">if</span> a &lt; b
           ^
SyntaxError: invalid syntax
</code></pre>
<h3 id="heading-semantic-error">Semantic error</h3>
<p>Semantic errors can lead to incorrect program behavior or unexpected results, even if the code runs without any exceptions</p>
<pre><code class="lang-python"><span class="hljs-comment"># Calculate the area of a circle</span>
radius = <span class="hljs-number">5</span>
area = <span class="hljs-number">3.14</span> * radius * radius
print(area)<span class="hljs-comment"># output = 78.5</span>
</code></pre>
<p>In this code snippet, the intention is to calculate the area of a circle using the formula <code>pi * radius * radius</code>. However, there is a semantic error in the calculation. Instead of using the accurate value of π (pi), an approximation of <code>3.14</code> is used.</p>
<pre><code class="lang-python"><span class="hljs-keyword">import</span> math

radius = <span class="hljs-number">5</span>
area = math.pi * radius * radius
print(area)<span class="hljs-comment"># output = 78.53981633974483</span>
</code></pre>
<h3 id="heading-runtime-errors">Runtime errors</h3>
<ul>
<li><p>Runtime errors are errors that occur while executing code at runtime.</p>
</li>
<li><p>They are caused by issues like dividing by zero, using undefined variables, performing operations on incompatible types, accessing invalid list indices, etc.</p>
</li>
<li><p>You can handle runtime errors using try/except blocks.</p>
</li>
<li><p>The try block contains the code that may raise an error, and the except block handles the error.</p>
<p>  <strong>To catch a</strong> <strong>ZeroDivisionError</strong>:</p>
<pre><code class="lang-python">  <span class="hljs-keyword">try</span>:  
      num / <span class="hljs-number">0</span>  
  <span class="hljs-keyword">except</span> ZeroDivisionError:
      print(<span class="hljs-string">"Cannot divide by zero"</span>)
</code></pre>
<p>  <strong>Catching TypeError:</strong></p>
<pre><code class="lang-python">  num = <span class="hljs-number">5</span>
  name = <span class="hljs-string">"nirmal"</span>
  <span class="hljs-keyword">try</span>:
       value = num + name  
  <span class="hljs-keyword">except</span> TypeError:
       print(<span class="hljs-string">"Incompatible types"</span>)
</code></pre>
<p>  <strong>To catch an IndexError:</strong></p>
<pre><code class="lang-python">  <span class="hljs-keyword">try</span>:
      list[invalid_index]  
  <span class="hljs-keyword">except</span> IndexError:
      print(<span class="hljs-string">"Invalid list index"</span>)
</code></pre>
</li>
</ul>
<h2 id="heading-tryexceptelsefinally">try…except…else…finally</h2>
<ul>
<li><p>In addition to try and except, you can use the else and finally keywords to further tune your code’s handling of exceptions.</p>
</li>
<li><p><code>else</code>: The optional <code>else</code> block is executed if no exceptions occur in the <code>try</code> block. It is used to specify code that should run only when no exceptions are raised.</p>
</li>
<li><p><code>finally</code>: The optional <code>finally</code> block is always executed, regardless of whether an exception occurred or not. It is used to specify code that should run regardless of the outcome, such as cleanup operations or resource release.</p>
<pre><code class="lang-python">  <span class="hljs-keyword">try</span>:
      print(<span class="hljs-string">"write some logic"</span>)
  <span class="hljs-keyword">except</span>:
      print(<span class="hljs-string">"this happens only if it fails"</span>)
  <span class="hljs-keyword">else</span>:
      print(<span class="hljs-string">"this happens only if it succeeds"</span>)
  <span class="hljs-keyword">finally</span>:
      print(<span class="hljs-string">"this happens no matter what"</span>)
</code></pre>
</li>
</ul>
<h2 id="heading-own-exception-classes">Own Exception Classes</h2>
<ul>
<li><p>In python, <code>raise</code> keyword is used to explicitly raise an exception or an error during the execution of a program.</p>
</li>
<li><p>It allows you to create custom exceptions or raise built-in exceptions to handle specific scenarios or error conditions.</p>
</li>
<li><p>Syntax : <strong>raise ExceptionType("Error message")</strong></p>
<pre><code class="lang-python">  n = int(input(<span class="hljs-string">"Enter any value::"</span>))
  <span class="hljs-keyword">if</span> n &lt; <span class="hljs-number">0</span>:
    <span class="hljs-keyword">raise</span> ValueError(<span class="hljs-string">"Value cannot be negative"</span>)
  <span class="hljs-keyword">else</span>:
    print(<span class="hljs-string">f"Enter value is :: <span class="hljs-subst">{n}</span>"</span>)
</code></pre>
</li>
</ul>
]]></content:encoded></item></channel></rss>