<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Manisha Kundrapu</title>
    <description>The latest articles on DEV Community by Manisha Kundrapu (@manishakundrapu).</description>
    <link>https://dev.to/manishakundrapu</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1019205%2Ffb82fc82-cd30-417f-863d-ed74cc53d43b.png</url>
      <title>DEV Community: Manisha Kundrapu</title>
      <link>https://dev.to/manishakundrapu</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/manishakundrapu"/>
    <language>en</language>
    <item>
      <title>Django Concepts</title>
      <dc:creator>Manisha Kundrapu</dc:creator>
      <pubDate>Tue, 04 Apr 2023 12:23:32 +0000</pubDate>
      <link>https://dev.to/manishakundrapu/django-concepts-4eol</link>
      <guid>https://dev.to/manishakundrapu/django-concepts-4eol</guid>
      <description>&lt;h2&gt;
  
  
  Settings file
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. What is the use of a transaction?
&lt;/h3&gt;

&lt;p&gt;In Django, a transaction is a way of grouping multiple database queries into a single, atomic operation. It ensures that either all the queries are successfully completed, or none of them are, even in the face of errors or unexpected events. This is an important feature for maintaining data integrity and consistency, especially in situations where multiple queries need to be executed together, and errors can occur.&lt;/p&gt;

&lt;p&gt;For example, when creating a new user in a Django application, several database queries may be required, including creating a new record in the user table, creating default permissions, and creating related records in other tables. These operations must be executed as a single, atomic unit, and any errors that occur must be properly handled to avoid leaving the system in an inconsistent state.&lt;/p&gt;

&lt;p&gt;In Django, you can use the &lt;code&gt;transaction.atomic()&lt;/code&gt; context manager to group multiple database queries into a single transaction. Any errors that occur within the context manager will cause the entire transaction to be rolled back. Additionally, Django provides other tools, such as &lt;code&gt;transaction.on_commit()&lt;/code&gt;, to perform actions after a transaction is committed, and &lt;code&gt;transaction.rollback()&lt;/code&gt; to explicitly roll back a transaction.&lt;/p&gt;

&lt;p&gt;Overall, using transactions in Django helps ensure that database operations are performed in a consistent and safe manner, and can help prevent data corruption and loss.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Why atomic transactions?
&lt;/h3&gt;

&lt;p&gt;Atomic transactions in Django are used to ensure the integrity and consistency of the database. When multiple operations are performed on a database, such as creating or updating multiple records, it is essential to ensure that all of the operations are completed successfully, or none of them are executed at all.&lt;/p&gt;

&lt;p&gt;Django provides a built-in support for database transactions using the atomic() function. When the atomic() function is used, it ensures that all database operations executed within its block are completed successfully, or if any error occurs, then all operations are rolled back to the initial state.&lt;/p&gt;

&lt;p&gt;For example, let's say you have two models A and B, and you want to create an instance of A and B simultaneously. Without using a transaction, if there is an error while creating B, A would still be created, leading to an inconsistent state. However, if you use an atomic transaction, either both A and B will be created, or neither will be created.&lt;/p&gt;

&lt;p&gt;In summary, atomic transactions in Django are used to ensure that database operations are completed successfully or rolled back to their initial state in case of errors, thus maintaining database consistency and integrity.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. What is secret key?
&lt;/h3&gt;

&lt;p&gt;In Django, the SECRET_KEY setting in the settings.py file is a value that is used to provide cryptographic signing for various authentication and security features , such as session cookies and password reset tokens. It is a randomly generated string of characters, and is an important security measure that helps protect your application from attacks such as cross-site scripting (XSS) and cross-site request forgery (CSRF). The SECRET_KEY is not the same thing as a user's password or login credentials, and should not be treated as such.&lt;/p&gt;

&lt;p&gt;It is important to note that the SECRET_KEY should never be hard-coded into your code or shared publicly. Instead, it should be stored in a secure location and passed to Django through an environment variable or a configuration file that is not checked into version control.&lt;/p&gt;

&lt;p&gt;To generate a new SECRET_KEY, you can use Django's built-in &lt;code&gt;get_random_secret_key&lt;/code&gt; function, like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;from django.core.management.utils import get_random_secret_key

SECRET_KEY &lt;span class="o"&gt;=&lt;/span&gt; get_random_secret_key&lt;span class="o"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will generate a new SECRET_KEY that can be used in your &lt;code&gt;settings.py&lt;/code&gt; file.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. What are the default Django apps inside it? Are there more?
&lt;/h3&gt;

&lt;p&gt;Django includes several default apps which are installed and enabled by default when creating a new Django project. &lt;/p&gt;

&lt;p&gt;These apps provide core functionality to the framework and include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;django.contrib.admin&lt;/strong&gt;: &lt;br&gt;
Provides a web-based administrative interface for the application.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;django.contrib.auth&lt;/strong&gt;: &lt;br&gt;
Provides authentication and authorization features for the application.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;django.contrib.contenttypes&lt;/strong&gt;: &lt;br&gt;
Provides content type functionality to the application.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;django.contrib.sessions&lt;/strong&gt;: &lt;br&gt;
Provides session management functionality to the application.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;django.contrib.messages&lt;/strong&gt;: &lt;br&gt;
Provides messaging functionality to the application.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;django.contrib.staticfiles&lt;/strong&gt;: &lt;br&gt;
Provides a way to serve static files like JavaScript, CSS, and images.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Other optional apps that can be installed and used in Django include:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;django.contrib.sites&lt;/strong&gt;: &lt;br&gt;
Provides site-specific functionality to the application.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;django.contrib.redirects&lt;/strong&gt;: &lt;br&gt;
Provides a way to manage URL redirections in the application.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;django.contrib.sitemaps&lt;/strong&gt;: &lt;br&gt;
Lets you specify the URLs that should be included in the site's XML sitemap.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;django.contrib.flatpages&lt;/strong&gt;: &lt;br&gt;
Provides a simple system for creating flat, static pages.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;django.contrib.syndication&lt;/strong&gt;: &lt;br&gt;
Makes it easy to syndicate content from your site with RSS and Atom feeds.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can also create your own custom apps and include them in your Django project.&lt;/p&gt;

&lt;h3&gt;
  
  
  5. What is middleware? What are different kinds of middleware ?
&lt;/h3&gt;

&lt;p&gt;In Django, middleware is a way to add extra functionality to the request/response processing pipeline. It sits between the web server and the view, and can modify the incoming request, outgoing response, or perform additional processing in between.&lt;/p&gt;

&lt;p&gt;Django middleware can be used for a variety of purposes, such as authentication, caching, logging, compressing response content, and more.&lt;/p&gt;

&lt;p&gt;There are different kinds of middleware in Django, including:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Process Request Middleware&lt;/strong&gt;: &lt;br&gt;
This type of middleware is executed before the view is called and can modify the request or perform additional processing before passing the request to the view.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Authentication Middleware&lt;/strong&gt;: &lt;br&gt;
This middleware is responsible for authenticating the user and setting the user object in the request object.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Session Middleware&lt;/strong&gt;: &lt;br&gt;
This middleware adds support for session handling in Django.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Cache Middleware&lt;/strong&gt;: &lt;br&gt;
This middleware provides caching support to the views.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Middleware for Compression&lt;/strong&gt;: &lt;br&gt;
This middleware compresses the content of the response to reduce its size and save bandwidth.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Exception Middleware&lt;/strong&gt;: &lt;br&gt;
This middleware catches and handles exceptions raised during the processing of a request.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Middleware for Response Headers&lt;/strong&gt;: &lt;br&gt;
This middleware can add or modify response headers.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Middleware for HTTPS&lt;/strong&gt;: &lt;br&gt;
This middleware redirects the request to HTTPS if the request is made over HTTP.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Django allows developers to write their own custom middleware to add functionality to the request/response pipeline. &lt;/p&gt;

&lt;p&gt;Middleware can be added to the middleware stack in the settings file, and they are executed in the order they are defined in the stack.&lt;/p&gt;

&lt;h3&gt;
  
  
  6. CSRF
&lt;/h3&gt;

&lt;p&gt;Cross-Site Request Forgery (CSRF) is a type of web vulnerability that allows attackers to perform actions on behalf of victims without their knowledge or consent. Django has built-in protection against CSRF attacks.&lt;/p&gt;

&lt;p&gt;The CSRF protection in Django is based on a random secret value stored in a CSRF cookie that only the server has access to. This value is included in every form rendered by Django by default as a hidden input field, and is also included in AJAX requests.&lt;/p&gt;

&lt;p&gt;To use the CSRF protection in Django, you need to include the &lt;code&gt;{% csrf_token %}&lt;/code&gt; template tag in your form. When the form is submitted, Django checks that the value of the CSRF cookie matches the value in the form submission.&lt;/p&gt;

&lt;p&gt;If you encounter CSRF verification errors in your Django application, it could be because the CSRF protection middleware is not enabled, or because the CSRF token was not included in the form submission. Make sure that the &lt;br&gt;
&lt;code&gt;{% csrf_token %}&lt;/code&gt; tag is included in your form and that the &lt;code&gt;django.middleware.csrf.CsrfViewMiddleware&lt;/code&gt; middleware is included in your MIDDLEWARE setting.&lt;/p&gt;

&lt;p&gt;It's important to enable the CSRF protection in your Django application to prevent possible CSRF attacks. Disabling the CSRF protection is not recommended, as it can leave your application vulnerable to attacks.&lt;/p&gt;
&lt;h3&gt;
  
  
  7. XSS
&lt;/h3&gt;

&lt;p&gt;Cross-Site Scripting (XSS) is another type of web vulnerability that can affect Django web applications. It allows an attacker to inject malicious scripts into the application, which can then execute in the context of a legitimate user's web page.&lt;/p&gt;

&lt;p&gt;Django provides protection against XSS attacks by automatically escaping dynamic content rendered in templates using the |safe filter. This ensures that any HTML code in the content is converted to HTML entities, which prevents it from being executed as code. You should also avoid using the |safe filter unless you are sure that the content is safe to render as raw HTML.&lt;/p&gt;

&lt;p&gt;To further protect your Django application from XSS attacks, you can use the &lt;code&gt;django.middleware.security.SecurityMiddleware&lt;/code&gt;middleware, which adds various security-related HTTP headers to the response. Some of these headers can help protect against XSS attacks, such as the X-XSS-Protection header, which enables or disables the browser's built-in XSS protection.&lt;/p&gt;

&lt;p&gt;It's important to implement proper security measures to prevent XSS attacks, especially in web applications that deal with sensitive data or handle user authentication. By following best practices and using the available security features provided by Django, you can minimize the risk of an XSS attack on your application.&lt;/p&gt;
&lt;h3&gt;
  
  
  8. Click Jacking
&lt;/h3&gt;

&lt;p&gt;Clickjacking is a type of security vulnerability where a user is tricked into clicking on a button or link that appears to be legitimate, but is actually hidden on top of another element on the page. This can be used to perform actions on behalf of the user without their knowledge or consent. Django provides built-in protection against clickjacking attacks by setting the X-Frame-Options header to prevent web pages from being embedded in iframes on other websites.&lt;/p&gt;

&lt;p&gt;The X-Frame-Options header is a HTTP response header that can be used to control whether a web page can be embedded in an iframe on another website. By setting this header, you can prevent clickjacking attacks by ensuring that your web pages cannot be embedded in iframes on other websites.&lt;/p&gt;

&lt;p&gt;In Django, you can set the X-Frame-Options header by configuring the MIDDLEWARE setting in your settings.py file. The following code sets the X-Frame-Options header to DENY, which prevents your web pages from being embedded in any iframes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;MIDDLEWARE &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;
    &lt;span class="c"&gt;# ...&lt;/span&gt;
    &lt;span class="s1"&gt;'django.middleware.clickjacking.XFrameOptionsMiddleware'&lt;/span&gt;,
&lt;span class="o"&gt;]&lt;/span&gt;

X_FRAME_OPTIONS &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'DENY'&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By default, the X-Frame-Options header is set to SAMEORIGIN, which allows your web pages to be embedded in iframes on the same domain. However, if you do not need to embed your web pages in iframes at all, it is recommended to set the header to DENY to provide maximum protection against clickjacking attacks.&lt;/p&gt;

&lt;p&gt;In addition to setting the X-Frame-Options header, you can also use JavaScript to prevent clickjacking attacks by detecting whether your web page is being displayed inside an iframe and taking appropriate action. However, this method is less reliable than using the X-Frame-Options header, as it may not work in all browsers and may be disabled by browser extensions or security software.&lt;/p&gt;

&lt;h3&gt;
  
  
  9. Any other middleware that is there?
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;AuthenticationMiddleware&lt;/strong&gt;: 
This middleware adds the user object to the request object after the user authenticates&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;CsrfViewMiddleware&lt;/strong&gt;: 
This middleware adds protection against CSRF (Cross-Site Request Forgery) attacks to your views by adding a CSRF token&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;SecurityMiddleware&lt;/strong&gt;: 
This middleware adds several security-related HTTP headers to your responses to improve the security of your site, such as X-XSS-Protection, X-Content-Type-Options, and more&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;SessionMiddleware&lt;/strong&gt;: 
This middleware manages sessions for your web application, providing a way to store information between requests for a specific user&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;CommonMiddleware&lt;/strong&gt;: 
This middleware contains several common operations used in web development, such as adding a slash to URLs that don't have one, handling redirects, and more.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Message Middleware&lt;/strong&gt;: 
This middleware is used to store and display messages to the user. It can be used to display success messages, error messages, and other feedback to the user.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cache Middleware&lt;/strong&gt;: 
This middleware is used to cache responses from your Django application. It can improve the performance of your application by reducing the number of requests to the server.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;GZip Middleware&lt;/strong&gt;: 
This middleware is used to compress responses from your Django application. It can reduce the size of responses and improve the performance of your application.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Locale Middleware&lt;/strong&gt;: 
This middleware is used to set the language and localization settings for your Django application. It can detect the user's preferred language and display content in that language.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These are just a few examples of the middleware available in Django. You can also write your own custom middleware to add specific functionality to your application.&lt;/p&gt;

&lt;h3&gt;
  
  
  10 . What is WSGI?
&lt;/h3&gt;

&lt;p&gt;WSGI stands for "Web Server Gateway Interface." It is a standard interface between web servers and Python web applications or frameworks, including Django. The purpose of WSGI is to provide a simple and universal interface that allows any web server to communicate with any Python web application or framework.&lt;/p&gt;

&lt;p&gt;When a client requests a web page from a Django application, the web server sends the request to the WSGI server, which then forwards the request to the Django application. The Django application processes the request, generates a response, and sends the response back to the WSGI server. The WSGI server then sends the response back to the web server, which finally sends the response back to the client.&lt;/p&gt;

&lt;p&gt;In Django, the WSGI server is typically provided by a third-party library, such as uWSGI or Gunicorn. Django includes a built-in WSGI handler in the form of the django.core.handlers.wsgi.WSGIHandler class, which is responsible for handling requests and generating responses.&lt;/p&gt;

&lt;p&gt;Using WSGI allows Django applications to be deployed on a wide variety of web servers, including Apache, Nginx, and many others. It also allows for greater flexibility in configuring and optimizing the web server and the Python application separately.&lt;/p&gt;

&lt;h2&gt;
  
  
  Models file
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. What is ondelete Cascade ?
&lt;/h3&gt;

&lt;p&gt;In Django, on_delete is an argument that can be used to specify the behavior of a foreign key relationship when the referenced object is deleted. on_delete specifies what should happen to the objects that have a foreign key pointing to the deleted object.&lt;/p&gt;

&lt;p&gt;on_delete can take several values, including:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;models.CASCADE&lt;/strong&gt;: &lt;br&gt;
When an object referenced by a foreign key is deleted, all objects that have a foreign key pointing to it will also be deleted. This can result in a cascading delete effect.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;models.PROTECT&lt;/strong&gt;: &lt;br&gt;
When an object referenced by a foreign key is deleted, the deletion will be prevented if there are any objects that have a foreign key pointing to it. This can prevent accidental deletion of important data.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;models.SET_NULL&lt;/strong&gt;: &lt;br&gt;
When an object referenced by a foreign key is deleted, the foreign key on all related objects will be set to NULL. This can result in data inconsistency if the foreign key is required.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;models.SET_DEFAULT&lt;/strong&gt;: &lt;br&gt;
When an object referenced by a foreign key is deleted, the foreign key on all related objects will be set to its default value.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;models.SET()&lt;/strong&gt;: &lt;br&gt;
When an object referenced by a foreign key is deleted, the foreign key on all related objects will be set to the specified value.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For example, if we have a Book model with a foreign key to an Author model, and we set &lt;code&gt;on_delete=models.CASCADE&lt;/code&gt;, then when an author is deleted, all books written by that author will also be deleted.&lt;/p&gt;

&lt;p&gt;It is important to choose the appropriate on_delete behavior based on the requirements and relationships of your data.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. A broad understanding of Fields and Validators available.
&lt;/h3&gt;

&lt;p&gt;In Django, fields are used to define the type of data that can be stored in a model. There are several built-in field types available in Django, such as CharField, TextField, IntegerField, FloatField, DateField, and DateTimeField, among others. Additionally, Django provides support for defining custom fields that can be used in a model.&lt;/p&gt;

&lt;p&gt;Validators, on the other hand, are used to ensure that the data entered by a user is valid and meets certain criteria. Validators can be applied to individual fields or to a form as a whole. Django provides several built-in validators that can be used to check if a field is required, if it has a maximum or minimum value, if it matches a regular expression, among others. Additionally, custom validators can be defined and used to validate form data based on specific business rules.&lt;/p&gt;

&lt;p&gt;Overall, fields and validators are important concepts in Django and are used to define the structure and behavior of models and forms. By understanding the available fields and validators, developers can create robust and secure applications that handle user data in a reliable way.&lt;/p&gt;

&lt;p&gt;Here is a brief overview of some of the most common fields and validators available in Django:&lt;/p&gt;

&lt;h4&gt;
  
  
  Fields:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;CharField&lt;/strong&gt;: 
A field that can store a string of up to a specified maximum length.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;TextField&lt;/strong&gt;: 
A field that can store a longer string of text.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;IntegerField&lt;/strong&gt;: 
A field that can store an integer.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;BooleanField&lt;/strong&gt;: 
A field that can store a boolean value.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;DateTimeField&lt;/strong&gt;: 
A field that can store a date and time.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;ForeignKey&lt;/strong&gt;: 
A field that defines a many-to-one relationship with another model.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;ManyToManyField&lt;/strong&gt;: 
A field that defines a many-to-many relationship with another model.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Validators:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;MaxValueValidator&lt;/strong&gt;: 
A validator that ensures that the input value is less than or equal to a specified maximum value.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;MinValueValidator&lt;/strong&gt;: 
A validator that ensures that the input value is greater than or equal to a specified minimum value.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;EmailValidator&lt;/strong&gt;: 
A validator that ensures that the input value is a valid email address.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;RegexValidator&lt;/strong&gt;: 
A validator that ensures that the input value matches a specified regular expression pattern.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;URLValidator&lt;/strong&gt;: 
A validator that ensures that the input value is a valid URL.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;MaxLengthValidator&lt;/strong&gt;: 
A validator that ensures that the input value is shorter than or equal to a specified maximum length.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  3. Understanding the difference between Python module and Python class?
&lt;/h3&gt;

&lt;p&gt;In Python, a module is a file containing Python code, while a class is a code template for creating objects that define the properties and methods of those objects. &lt;/p&gt;

&lt;p&gt;Here are some key differences between Python modules and classes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;A module is a file containing Python code, while a class is a code template for creating objects.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A module can contain multiple classes, functions, and variables, while a class is a specific construct for defining object behavior and properties.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Modules are typically used to organize related code into a single file, while classes are used to define the structure and behavior of objects.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Modules are imported using the import statement, while classes are instantiated using the class keyword.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In Django, modules are commonly used to organize related functionality into separate files, such as models, views, forms, and templates. Classes are used to define the behavior and properties of those objects.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;For example, in a Django application, we might have a module called models.py that defines several classes, such as User, Post, and Comment, each representing a different type of object in the application. We can then import these classes into other modules, such as views.py, to define the behavior of those objects in response to HTTP requests.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Django ORM
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. Using ORM queries in Django Shell
&lt;/h3&gt;

&lt;p&gt;Django's ORM provides an interactive shell that allows you to experiment with database queries and interact with the database directly from the command line. &lt;/p&gt;

&lt;p&gt;Here's how you can use the ORM queries in Django shell:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Open your terminal and navigate to the root directory of your Django project.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Activate your virtual environment, if you have one.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Type python manage.py shell to open the Django shell.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Once you're in the shell, you can start typing ORM queries to interact with your database. For example, you could retrieve all of the objects from a particular model using the following command:&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; from myapp.models import MyModel
&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; MyModel.objects.all&lt;span class="o"&gt;()&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will return a QuerySet object containing all of the objects in the MyModel table.&lt;/p&gt;

&lt;p&gt;You can also filter the QuerySet based on certain criteria. For example, to retrieve all of the objects in the MyModel table where the name field is equal to "John", you could use the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; MyModel.objects.filter&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'John'&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can chain multiple filters together to refine your query even further. For example, to retrieve all of the objects in the MyModel table where the name field is equal to "John" and the age field is greater than 30, you could use the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; MyModel.objects.filter&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'John'&lt;/span&gt;, &lt;span class="nv"&gt;age__gt&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;30&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also use other ORM methods such as exclude(), order_by(), values(), and annotate() to further manipulate your QuerySet.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;When you're finished with the shell, you can exit by typing exit() or pressing Ctrl+D.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Overall, using the Django shell with ORM queries is a powerful way to interact with your database and test out queries before incorporating them into your application.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Turning ORM to SQL in Django Shell
&lt;/h3&gt;

&lt;p&gt;Django's ORM provides a way to translate ORM queries into SQL statements. &lt;/p&gt;

&lt;p&gt;This can be useful for debugging or optimizing queries, as it allows you to see the actual SQL that's being executed by the database. &lt;/p&gt;

&lt;p&gt;Here's how you can turn ORM queries into SQL in the Django shell:&lt;/p&gt;

&lt;p&gt;Once you're in the shell, you can start typing ORM queries to interact with your database. &lt;/p&gt;

&lt;p&gt;For example, you could retrieve all of the objects from a particular model using the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; from myapp.models import MyModel
&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; MyModel.objects.all&lt;span class="o"&gt;()&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To see the SQL that's being executed for this query, you can call the query attribute on the QuerySet object, like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; print&lt;span class="o"&gt;(&lt;/span&gt;MyModel.objects.all&lt;span class="o"&gt;()&lt;/span&gt;.query&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will print out the SQL that's being executed to retrieve all of the objects from the MyModel table.&lt;/p&gt;

&lt;p&gt;You can also turn more complex ORM queries into SQL by calling the query attribute on the QuerySet object. &lt;/p&gt;

&lt;p&gt;For example, to see the SQL that's being executed for a filtered query, you could use the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; print&lt;span class="o"&gt;(&lt;/span&gt;MyModel.objects.filter&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'John'&lt;/span&gt;, &lt;span class="nv"&gt;age__gt&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;30&lt;span class="o"&gt;)&lt;/span&gt;.query&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will print out the SQL that's being executed to retrieve all of the objects in the MyModel table where the name field is equal to "John" and the age field is greater than 30.&lt;/p&gt;

&lt;p&gt;Overall, turning ORM queries into SQL statements in the Django shell is a powerful way to debug and optimize your queries. It allows you to see the exact SQL that's being executed by the database, which can be useful for identifying performance bottlenecks or other issues with your queries.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. What are Aggregations?
&lt;/h3&gt;

&lt;p&gt;Aggregations in Django are a way to perform various mathematical operations on a set of values within a QuerySet. They allow you to calculate statistics and summarize data based on certain criteria, such as the average or sum of a particular field in the database table. Django provides a set of built-in aggregation functions that you can use in your code.&lt;/p&gt;

&lt;p&gt;Here are some of the built-in aggregation functions in Django:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Avg&lt;/strong&gt;: Calculates the average value of a particular field in the QuerySet.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Count&lt;/strong&gt;: Returns the number of objects in the QuerySet.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Max&lt;/strong&gt;: Returns the maximum value of a particular field in the QuerySet.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Min&lt;/strong&gt;: Returns the minimum value of a particular field in the QuerySet.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Sum&lt;/strong&gt;: Calculates the sum of a particular field in the QuerySet.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can use these aggregation functions in combination with other QuerySet methods to create complex queries. &lt;/p&gt;

&lt;p&gt;For example, you could use the filter() method to narrow down the QuerySet to a specific subset of objects, and then use the Avg() function to calculate the average value of a particular field in that subset.&lt;/p&gt;

&lt;p&gt;Here's an example of using the Avg() function to calculate the average price of all the products in a database table:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;
from myapp.models import Product

average_price &lt;span class="o"&gt;=&lt;/span&gt; Product.objects.all&lt;span class="o"&gt;()&lt;/span&gt;.aggregate&lt;span class="o"&gt;(&lt;/span&gt;Avg&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'price'&lt;/span&gt;&lt;span class="o"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code retrieves all the objects from the Product table and calculates the average value of the price field using the Avg() function. &lt;/p&gt;

&lt;p&gt;The result is returned as a dictionary, with the name of the aggregation function as the key and the result as the value.&lt;/p&gt;

&lt;p&gt;Overall, aggregations are a powerful way to perform calculations and summarize data within a QuerySet in Django. They allow you to create complex queries and extract useful insights from your data.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. What are Annotations?
&lt;/h3&gt;

&lt;p&gt;In Django, annotations are a way to provide additional information or computations on each object in a QuerySet. They allow you to enrich the data returned from a queryset with additional fields that are not part of the database schema. Annotations are similar to aggregations in that they both operate on subsets of data, but the difference is that annotations are applied to each object in the QuerySet individually.&lt;/p&gt;

&lt;p&gt;Annotations are performed using the annotate() function in Django, and can be used with a wide range of aggregation functions, such as Count(), Sum(), Avg(), Max(), and Min(). The resulting QuerySet will contain the original objects, as well as the annotated fields.&lt;/p&gt;

&lt;p&gt;Here's an example of using the annotate() function to perform a count of related objects for each object in a queryset:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;from myapp.models import Author, Book
book_counts &lt;span class="o"&gt;=&lt;/span&gt; Author.objects.annotate&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;num_books&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;Count&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'book'&lt;/span&gt;&lt;span class="o"&gt;))&lt;/span&gt;
&lt;span class="k"&gt;for &lt;/span&gt;author &lt;span class="k"&gt;in &lt;/span&gt;book_counts:
    print&lt;span class="o"&gt;(&lt;/span&gt;author.name, author.num_books&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, Author and Book are Django models. We use the annotate() function to annotate the QuerySet with a field called num_books, which is a count of related Book objects for each Author. We then iterate over the results and print out the author name and the number of books they have written.&lt;/p&gt;

&lt;p&gt;Overall, annotations are a powerful way to add additional data to a QuerySet based on calculations or aggregations. They allow you to perform complex operations on your data without modifying the underlying database schema, and can be a useful tool for generating reports or visualizations based on your data.&lt;/p&gt;

&lt;h3&gt;
  
  
  5. What is a migration file? Why is it needed?
&lt;/h3&gt;

&lt;p&gt;In Django, a migration file is an autogenerated Python script that represents a set of changes to your database schema. It contains instructions for creating, modifying, or deleting database tables, columns, indexes, and other database schema objects.&lt;/p&gt;

&lt;p&gt;Migration files are needed for several reasons:&lt;/p&gt;

&lt;p&gt;They allow you to version control your changes to the database schema, which makes it easier to track changes and revert to previous versions if necessary.&lt;br&gt;
They make it easy to deploy changes to the database schema to production systems, because you can simply apply the migration files to the production database.&lt;br&gt;
They provide a way to update the database schema in a consistent and reliable manner without having to manually make changes to the database or write custom scripts.&lt;/p&gt;

&lt;p&gt;When you create a new model or modify an existing one in Django, you can generate a new migration file using the makemigrations management command. This command analyzes the changes you've made to your models and generates a new migration file that captures those changes. You can then apply the migration using the migrate management command, which updates your database schema to reflect the changes in the migration file.&lt;/p&gt;

&lt;p&gt;Here's an example of generating and applying a migration in Django:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Create a new model&lt;/span&gt;
class Book&lt;span class="o"&gt;(&lt;/span&gt;models.Model&lt;span class="o"&gt;)&lt;/span&gt;:
    title &lt;span class="o"&gt;=&lt;/span&gt; models.CharField&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;max_length&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;100&lt;span class="o"&gt;)&lt;/span&gt;
    author &lt;span class="o"&gt;=&lt;/span&gt; models.CharField&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;max_length&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;100&lt;span class="o"&gt;)&lt;/span&gt;
    published_date &lt;span class="o"&gt;=&lt;/span&gt; models.DateField&lt;span class="o"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Generate a new migration file&lt;/span&gt;
python manage.py makemigrations

&lt;span class="c"&gt;# Apply the migrations&lt;/span&gt;
python manage.py migrate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we create a new Book model with three fields, and then generate a new migration file using the makemigrations command. This command analyzes the changes we've made to our models and generates a new migration file that captures those changes. We can then apply the migration using the migrate command, which updates our database schema to reflect the changes in the migration file.&lt;/p&gt;

&lt;p&gt;Overall, migration files are a critical component of the Django ORM. They allow you to manage changes to your database schema over time, version control those changes, and apply them in a consistent and automated way. Without migrations, managing changes to your database schema can be a time-consuming and error-prone process.&lt;/p&gt;

&lt;h3&gt;
  
  
  6. What are SQL transactions? (non ORM concept)
&lt;/h3&gt;

&lt;p&gt;In general, an SQL transaction is a series of queries executed as a single unit of work, where all of the queries either succeed together or fail together. In Django, SQL transactions are used to ensure that database operations are applied atomically and reliably.&lt;/p&gt;

&lt;p&gt;When you perform a database operation in Django, it is typically executed within a transaction. Transactions can ensure that changes to the database are atomic, meaning that either all of the changes are applied, or none of them are. If a transaction fails, all of the changes made within the transaction are rolled back, so that the database remains in a consistent state. This is important for ensuring data integrity and consistency.&lt;/p&gt;

&lt;p&gt;In Django, you can control transactions using the transaction.atomic() decorator, which wraps a block of database operations in a transaction. There are also lower-level functions like transaction.commit() and transaction.rollback() which allow you to explicitly commit or rollback a transaction.&lt;/p&gt;

&lt;p&gt;Overall, transactions are an important concept in SQL and databases in general, and they are essential for ensuring data consistency and integrity in Django applications as well.&lt;/p&gt;

&lt;h3&gt;
  
  
  7. What are atomic transactions?
&lt;/h3&gt;

&lt;p&gt;In the context of Django, atomic transactions refer to a way of ensuring the atomicity of database transactions. Atomicity is one of the defining properties of database transactions, and it means that a set of database operations must be executed as a single, indivisible unit of work. This ensures that the database is always in a consistent state, even if there are errors or interruptions during the transaction.&lt;/p&gt;

&lt;p&gt;Django provides a single API , transaction.atomic(), to control database transactions. When you use transaction.atomic(), Django starts a transaction before calling a view function, and if the view produces a response without errors , Django commits the transaction. If there are any errors, Django rolls back the transaction, undoing any changes that were made to the database during the transaction.&lt;/p&gt;

&lt;p&gt;Using atomic transactions in Django is important any time you have a multi-step process that involves making changes to the database. By using atomic transactions, you can ensure that the database remains in a consistent state, even if errors occur during the transaction.&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://docs.djangoproject.com/en/3.2/topics/settings/"&gt;https://docs.djangoproject.com/en/3.2/topics/settings/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://docs.djangoproject.com/en/3.2/topics/http/middleware/"&gt;https://docs.djangoproject.com/en/3.2/topics/http/middleware/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://docs.djangoproject.com/en/3.2/ref/csrf/"&gt;https://docs.djangoproject.com/en/3.2/ref/csrf/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://docs.djangoproject.com/en/3.2/topics/security/#cross-site-scripting-xss-protection"&gt;https://docs.djangoproject.com/en/3.2/topics/security/#cross-site-scripting-xss-protection&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://docs.djangoproject.com/en/3.2/topics/security/#clickjacking-protection"&gt;https://docs.djangoproject.com/en/3.2/topics/security/#clickjacking-protection&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://docs.djangoproject.com/en/3.2/howto/deployment/wsgi/"&gt;https://docs.djangoproject.com/en/3.2/howto/deployment/wsgi/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://docs.djangoproject.com/en/4.1/topics/db/aggregation/"&gt;https://docs.djangoproject.com/en/4.1/topics/db/aggregation/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>django</category>
      <category>python</category>
    </item>
    <item>
      <title>Revision 10-03-2023</title>
      <dc:creator>Manisha Kundrapu</dc:creator>
      <pubDate>Fri, 10 Mar 2023 07:05:01 +0000</pubDate>
      <link>https://dev.to/manishakundrapu/revision-10-03-2023-5258</link>
      <guid>https://dev.to/manishakundrapu/revision-10-03-2023-5258</guid>
      <description>&lt;h4&gt;
  
  
  1. In JavaScript how do you check whether an object is an array or not?
&lt;/h4&gt;

&lt;p&gt;In JavaScript, you can check whether an object is an array or not using the Array.isArray() method.&lt;/p&gt;

&lt;h4&gt;
  
  
  2. Is the data list tag and select tag the same?
&lt;/h4&gt;

&lt;p&gt;While the  and  HTML tags are both used to present a list of options to the user, they are not the same.&lt;/p&gt;

&lt;p&gt;The  tag is used to create a dropdown list of options that the user can select from. When the user clicks on the dropdown, a list of options is displayed and the user can choose one of the options. The selected option is then displayed in the dropdown.&lt;/p&gt;

&lt;p&gt;The  tag, on the other hand, is used to create a list of options that are displayed as suggestions while the user is typing in an input field. When the user types a character in the input field, a list of suggested options is displayed below the input field. The user can then select one of the suggested options, or continue typing to refine the suggestions.&lt;/p&gt;

&lt;h4&gt;
  
  
  3. When merge conflict occurs in git?
&lt;/h4&gt;

&lt;p&gt;A merge conflict in Git occurs when two or more developers make changes to the same part of a file, and those changes conflict with each other.&lt;/p&gt;

&lt;h4&gt;
  
  
  4. Why do we use the typeof operator in JavaScript?
&lt;/h4&gt;

&lt;p&gt;The typeof operator is used to determine the data type of a given value or expression. &lt;/p&gt;

&lt;p&gt;It returns a string indicating the type of the operand.&lt;/p&gt;

&lt;h4&gt;
  
  
  5. What is the difference between "===" and  "==" in JavaScript?
&lt;/h4&gt;

&lt;p&gt;The == operator checks whether the values of two operands are equal or not, regardless of their data types. If the values are equal, it returns True. If they are not equal, it returns False.&lt;/p&gt;

&lt;p&gt;The === operator also compares two values for equality, but it does take their data type into account. This means that if the two values have different data types, the comparison will return false.&lt;/p&gt;

&lt;h4&gt;
  
  
  6. What is the difference between CSS border and outline?
&lt;/h4&gt;

&lt;p&gt;CSS border properties allow us to set the style, color, and width of the border. &lt;/p&gt;

&lt;p&gt;CSS outline property allows us to draw a line around the element, outside the border.&lt;/p&gt;

&lt;h4&gt;
  
  
  7. When do we use let and const instead of var in JavaScript?
&lt;/h4&gt;

&lt;p&gt;var declarations are globally scoped or function scoped while let and const are block scoped. &lt;/p&gt;

&lt;p&gt;var variables can be updated and re-declared within its scope.&lt;/p&gt;

&lt;p&gt;let variables can be updated but not re-declared, const variables can neither be updated nor re-declared. &lt;/p&gt;

&lt;p&gt;They are all hoisted to the top of their scope.&lt;/p&gt;

&lt;h4&gt;
  
  
  8. What is the difference between shared lock and exclusive lock in a transaction?
&lt;/h4&gt;

&lt;p&gt;A shared lock allows multiple transactions to read the same data concurrently, but only one transaction can modify the data at a time.&lt;/p&gt;

&lt;p&gt;An exclusive lock allows a single transaction to modify the data while blocking all other transactions from reading or modifying it.&lt;/p&gt;

&lt;h4&gt;
  
  
  9. What is hoisting in JavaScript?
&lt;/h4&gt;

&lt;p&gt;Hoisting is a mechanism where variable and function declarations are moved to the top of their respective scopes, before the code is executed. This means that variables and functions can be used in code before they are declared, without causing a syntax error.&lt;/p&gt;

&lt;h4&gt;
  
  
  10. How is user authentication data fetched from forms in web pages?
&lt;/h4&gt;

&lt;p&gt;User authentication data can be done using JWT where it will be added as a middleware in the backend to check the credentials that is stored in the backend in the form of token.&lt;/p&gt;

&lt;p&gt;In a JWT-based authentication system, user authentication is done using the following steps:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The user enters their credentials into a form on a web page and submits the form.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The server verifies the user's credentials and, if they are valid, generates a JSON Web Token (JWT) containing a payload with the user's information (such as their user ID, role, and any other relevant data) and signs it using a secret key. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The JWT is then returned to the client  and is included in all subsequent requests made by the client.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The backend typically has a middleware (or multiple middlewares) that are responsible for handling user authentication. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;When a request is received by the backend, the JWT is extracted from the request and verified using the same secret key that was used to sign it. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If the JWT is valid, the user is considered authenticated and the request is processed. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If the JWT is invalid (e.g., because it has been tampered with or has expired), the user is considered unauthenticated and the request is rejected.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  11. What is the git command to update username and email locally?
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git config user.name "NewUserName"
git config user.email "new.email@example.com"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  12. What is an expression and statement in JavaScript?
&lt;/h3&gt;

&lt;p&gt;An expression is any piece of code that can be evaluated to produce a value. &lt;/p&gt;

&lt;p&gt;For example, 5 + 3 is an expression that evaluates to the value 8. &lt;/p&gt;

&lt;p&gt;Other examples of expressions include variable references, function calls, and logical operators.&lt;/p&gt;

&lt;p&gt;A statement, on the other hand, is a complete unit of code that performs some action. &lt;/p&gt;

&lt;p&gt;It typically ends with a semicolon ;. &lt;/p&gt;

&lt;p&gt;Examples of statements in JavaScript include variable declarations, function declarations, loops, conditional statements, and assignments.&lt;/p&gt;

&lt;p&gt;Here are some examples to illustrate the difference between expressions and statements:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
// Expression example
let sum = 5 + 3; // The expression "5 + 3" evaluates to the value 8

// Statement example
if (sum === 8) {
  console.log("The sum is 8!"); // The entire "if" block is a statement that logs a message to the console
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, 5 + 3 is an expression that is assigned to the variable sum, which is a statement. The if block is a statement that includes an expression (sum === 8) as its condition, and another statement (console.log()) as its body.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>HTML CSS Concepts</title>
      <dc:creator>Manisha Kundrapu</dc:creator>
      <pubDate>Thu, 02 Mar 2023 06:48:34 +0000</pubDate>
      <link>https://dev.to/manishakundrapu/html-css-concepts-536a</link>
      <guid>https://dev.to/manishakundrapu/html-css-concepts-536a</guid>
      <description>&lt;p&gt;The following are some of the concepts that are included :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Box Model&lt;/li&gt;
&lt;li&gt;Inline versus Block Elements&lt;/li&gt;
&lt;li&gt;Positioning: Relative/Absolute&lt;/li&gt;
&lt;li&gt;Common CSS structural classes&lt;/li&gt;
&lt;li&gt;Common CSS syling classes&lt;/li&gt;
&lt;li&gt;CSS Specificity&lt;/li&gt;
&lt;li&gt;CSS Responsive Queries&lt;/li&gt;
&lt;li&gt;Flexbox/Grid&lt;/li&gt;
&lt;li&gt;Common header meta tags&lt;/li&gt;
&lt;li&gt;Open Graph Tags&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  1. Box Model
&lt;/h2&gt;

&lt;p&gt;According to the box model concept, every element on a page is a rectangular box and may have width, height, padding, borders, and margins.&lt;/p&gt;

&lt;p&gt;It refers to the way in which a box element is rendered on a web page. &lt;/p&gt;

&lt;p&gt;It consists of the content area, padding area, border area, and margin area.&lt;/p&gt;

&lt;p&gt;Here is a breakdown of each component of the box model:&lt;/p&gt;

&lt;h3&gt;
  
  
  Content area:
&lt;/h3&gt;

&lt;p&gt;This is where the actual content of the element is displayed. &lt;/p&gt;

&lt;p&gt;The content area is determined by the height and width properties.&lt;/p&gt;

&lt;h3&gt;
  
  
  Padding area:
&lt;/h3&gt;

&lt;p&gt;This is the space between the content and the border. &lt;/p&gt;

&lt;p&gt;Padding is used to add space around the content of an element. &lt;/p&gt;

&lt;p&gt;The padding area is determined by the padding property.&lt;/p&gt;

&lt;h3&gt;
  
  
  Border area:
&lt;/h3&gt;

&lt;p&gt;This is the area around the padding and content. &lt;/p&gt;

&lt;p&gt;The border is used to add a border around an element. &lt;/p&gt;

&lt;p&gt;The border area is determined by the border property.&lt;/p&gt;

&lt;h3&gt;
  
  
  Margin area:
&lt;/h3&gt;

&lt;p&gt;This is the space between the border and the outside edge of the element. &lt;/p&gt;

&lt;p&gt;Margin is used to add space between elements. &lt;/p&gt;

&lt;p&gt;The margin area is determined by the margin property.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Total width&lt;/strong&gt;: &lt;/p&gt;

&lt;p&gt;margin-right + border-right + padding-right + width + &lt;br&gt;
 padding-left + border-left + margin-left&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Total height&lt;/strong&gt;: &lt;/p&gt;

&lt;p&gt;margin-top + border-top + padding-top + height + &lt;br&gt;
padding-bottom + border-bottom + margin-bottom&lt;/p&gt;

&lt;p&gt;Here are some examples of how the box model is used in CSS:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example 1&lt;/strong&gt;: Adding padding and border to an element&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&amp;lt;div &lt;span class="nv"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"box"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
  This is some text &lt;span class="k"&gt;in &lt;/span&gt;a box.
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;.box &lt;span class="o"&gt;{&lt;/span&gt;
  padding: 10px&lt;span class="p"&gt;;&lt;/span&gt;
  border: 1px solid black&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we've added padding and a border to the div element. &lt;/p&gt;

&lt;p&gt;The padding property adds 10 pixels of space around the content of the element, and the border property adds a 1-pixel border around the element.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example 2&lt;/strong&gt;: Setting the height and width of an element&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&amp;lt;div &lt;span class="nv"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"box"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
  This is some text &lt;span class="k"&gt;in &lt;/span&gt;a box.
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;.box &lt;span class="o"&gt;{&lt;/span&gt;
  width: 200px&lt;span class="p"&gt;;&lt;/span&gt;
  height: 100px&lt;span class="p"&gt;;&lt;/span&gt;
  border: 1px solid black&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we've set the width and height properties of the div element. &lt;/p&gt;

&lt;p&gt;This determines the size of the content area of the element. &lt;/p&gt;

&lt;p&gt;We've also added a 1-pixel border around the element.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example 3&lt;/strong&gt;: Adding margin to an element&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;
&amp;lt;div &lt;span class="nv"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"box1"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
  This is box 1.
&amp;lt;/div&amp;gt;
&amp;lt;div &lt;span class="nv"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"box2"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
  This is box 2.
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;.box1 &lt;span class="o"&gt;{&lt;/span&gt;
  border: 1px solid black&lt;span class="p"&gt;;&lt;/span&gt;
  margin: 10px&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

.box2 &lt;span class="o"&gt;{&lt;/span&gt;
  border: 1px solid black&lt;span class="p"&gt;;&lt;/span&gt;
  margin: 20px&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we've added margin to two div elements. &lt;/p&gt;

&lt;p&gt;The margin property adds space between the border of the element and the next element on the page. &lt;/p&gt;

&lt;p&gt;In this case, box1 has a margin of 10 pixels and box2 has a margin of 20 pixels.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. Inline versus Block Elements
&lt;/h2&gt;

&lt;p&gt;In HTML and CSS, elements can be classified as either inline or block elements, depending on how they are displayed on the webpage.&lt;/p&gt;

&lt;h3&gt;
  
  
  Block Elements:
&lt;/h3&gt;

&lt;p&gt;Block-level elements are those which create a rectangular block on the webpage that occupies the entire width of their parent container. &lt;/p&gt;

&lt;p&gt;Examples of block-level elements include div, p, h1, ul, ol, table, and form. &lt;/p&gt;

&lt;p&gt;Block-level elements can have margin, padding, and borders applied to them, and they will start on a new line.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&amp;lt;div&amp;gt;
  &amp;lt;h1&amp;gt;This is a heading&amp;lt;/h1&amp;gt;
  &amp;lt;p&amp;gt;This is a paragraph.&amp;lt;/p&amp;gt;
  &amp;lt;ul&amp;gt;
    &amp;lt;li&amp;gt;List item 1&amp;lt;/li&amp;gt;
    &amp;lt;li&amp;gt;List item 2&amp;lt;/li&amp;gt;
  &amp;lt;/ul&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the div, h1, p, and ul elements are all block-level elements, and will each start on a new line, taking up the full width of their parent container.&lt;/p&gt;

&lt;h3&gt;
  
  
  Inline Elements:
&lt;/h3&gt;

&lt;p&gt;Inline elements are those which are displayed inline with the text. &lt;/p&gt;

&lt;p&gt;Examples of inline elements include a, span, img, and button. &lt;/p&gt;

&lt;p&gt;Inline elements do not start on a new line, and their width is determined by their content.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&amp;lt;p&amp;gt;This is a paragraph with an &amp;lt;a &lt;span class="nv"&gt;href&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"#"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;inline &lt;span class="nb"&gt;link&lt;/span&gt;&amp;lt;/a&amp;gt;.&amp;lt;/p&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the p and a elements are both inline. &lt;/p&gt;

&lt;p&gt;The a element is displayed inline with the text of the paragraph, and does not start on a new line.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Positioning: Relative/Absolute
&lt;/h2&gt;

&lt;p&gt;In CSS, positioning refers to the way elements are positioned on the web page. &lt;/p&gt;

&lt;p&gt;There are different types of positioning available in CSS, including relative and absolute positioning.&lt;/p&gt;

&lt;h3&gt;
  
  
  Relative Positioning:
&lt;/h3&gt;

&lt;p&gt;Relative positioning is the default positioning of elements on a web page. &lt;/p&gt;

&lt;p&gt;With relative positioning, an element is positioned relative to its normal position in the document flow. &lt;/p&gt;

&lt;p&gt;This means that the element will still take up space in the normal document flow, but it can be moved around using CSS properties such as top, bottom, left, and right.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;div &lt;span class="o"&gt;{&lt;/span&gt;
  position: relative&lt;span class="p"&gt;;&lt;/span&gt;
  top: 20px&lt;span class="p"&gt;;&lt;/span&gt;
  left: 50px&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the div element is set to &lt;br&gt;
position: relative, which means it will still take up space in the normal document flow. &lt;/p&gt;

&lt;p&gt;However, it has also been moved 20 pixels down and 50 pixels to the right using the top and left properties.&lt;/p&gt;
&lt;h3&gt;
  
  
  Absolute Positioning:
&lt;/h3&gt;

&lt;p&gt;Absolute positioning allows an element to be positioned relative to its nearest positioned ancestor, or relative to the initial containing block if no positioned ancestor is found. &lt;/p&gt;

&lt;p&gt;With absolute positioning, the element is taken out of the normal document flow, and it will not affect the position of other elements on the page.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;div &lt;span class="o"&gt;{&lt;/span&gt;
  position: absolute&lt;span class="p"&gt;;&lt;/span&gt;
  top: 20px&lt;span class="p"&gt;;&lt;/span&gt;
  left: 50px&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the div element is set to &lt;br&gt;
position: absolute, which means it will be taken out of the normal document flow. &lt;/p&gt;

&lt;p&gt;It has also been positioned 20 pixels down and 50 pixels to the right of its nearest positioned ancestor element.&lt;/p&gt;

&lt;p&gt;It's important to note that if an element is absolutely positioned, its position will be fixed relative to the browser window, and will not change if the user scrolls the page. &lt;/p&gt;

&lt;p&gt;This can be useful for creating fixed position elements such as navigation bars or headers.&lt;/p&gt;
&lt;h2&gt;
  
  
  4. Common CSS structural classes
&lt;/h2&gt;

&lt;p&gt;There are several common CSS structural classes that are used to style web page elements. &lt;/p&gt;

&lt;p&gt;Here are some examples:&lt;/p&gt;
&lt;h3&gt;
  
  
  Container:
&lt;/h3&gt;

&lt;p&gt;This class is used to define the outermost element of a web page. &lt;/p&gt;

&lt;p&gt;It is typically used to set the maximum width of the page and center its content.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;.container &lt;span class="o"&gt;{&lt;/span&gt;
  max-width: 1200px&lt;span class="p"&gt;;&lt;/span&gt;
  margin: 0 auto&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Grid:
&lt;/h3&gt;

&lt;p&gt;This class is used to create a grid layout for a web page. &lt;/p&gt;

&lt;p&gt;It is typically used to divide the page into rows and columns to organize content.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;.grid &lt;span class="o"&gt;{&lt;/span&gt;
  display: grid&lt;span class="p"&gt;;&lt;/span&gt;
  grid-template-columns: repeat&lt;span class="o"&gt;(&lt;/span&gt;3, 1fr&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  grid-gap: 20px&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Flex:
&lt;/h3&gt;

&lt;p&gt;This class is used to create a flexible layout for a web page. &lt;/p&gt;

&lt;p&gt;It is typically used to align and distribute elements within a container.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;.flex &lt;span class="o"&gt;{&lt;/span&gt;
  display: flex&lt;span class="p"&gt;;&lt;/span&gt;
  justify-content: center&lt;span class="p"&gt;;&lt;/span&gt;
  align-items: center&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Header:
&lt;/h3&gt;

&lt;p&gt;This class is used to style the header section of a web page. &lt;/p&gt;

&lt;p&gt;It is typically used to set the background color, font size, and font style of the heading.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;.header &lt;span class="o"&gt;{&lt;/span&gt;
  background-color: &lt;span class="c"&gt;#333;&lt;/span&gt;
  color: &lt;span class="c"&gt;#fff;&lt;/span&gt;
  font-size: 24px&lt;span class="p"&gt;;&lt;/span&gt;
  font-family: Arial, sans-serif&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Navigation:
&lt;/h3&gt;

&lt;p&gt;This class is used to style the navigation menu of a web page. &lt;/p&gt;

&lt;p&gt;It is typically used to set the background color, font size, and font style of the menu items.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;.navigation &lt;span class="o"&gt;{&lt;/span&gt;
  background-color: &lt;span class="c"&gt;#f1f1f1;&lt;/span&gt;
  font-size: 16px&lt;span class="p"&gt;;&lt;/span&gt;
  font-family: Arial, sans-serif&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Footer:
&lt;/h3&gt;

&lt;p&gt;This class is used to style the footer section of a web page.&lt;/p&gt;

&lt;p&gt;It is typically used to set the background color, font size, and font style of the footer.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;.footer &lt;span class="o"&gt;{&lt;/span&gt;
  background-color: &lt;span class="c"&gt;#333;&lt;/span&gt;
  color: &lt;span class="c"&gt;#fff;&lt;/span&gt;
  font-size: 16px&lt;span class="p"&gt;;&lt;/span&gt;
  font-family: Arial, sans-serif&lt;span class="p"&gt;;&lt;/span&gt;
  text-align: center&lt;span class="p"&gt;;&lt;/span&gt;
  padding: 20px&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Section:
&lt;/h3&gt;

&lt;p&gt;This class is used to create a section of a web page. &lt;/p&gt;

&lt;p&gt;It is typically used to group related content together and apply styling to the section as a whole.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;.section &lt;span class="o"&gt;{&lt;/span&gt;
  background-color: &lt;span class="c"&gt;#f1f1f1;&lt;/span&gt;
  padding: 20px&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Button:
&lt;/h3&gt;

&lt;p&gt;This class is used to style a button element on a web page. &lt;/p&gt;

&lt;p&gt;It is typically used to set the background color, font size, and font style of the button.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;.button &lt;span class="o"&gt;{&lt;/span&gt;
  background-color: &lt;span class="c"&gt;#333;&lt;/span&gt;
  color: &lt;span class="c"&gt;#fff;&lt;/span&gt;
  font-size: 16px&lt;span class="p"&gt;;&lt;/span&gt;
  font-family: Arial, sans-serif&lt;span class="p"&gt;;&lt;/span&gt;
  border: none&lt;span class="p"&gt;;&lt;/span&gt;
  padding: 10px 20px&lt;span class="p"&gt;;&lt;/span&gt;
  border-radius: 5px&lt;span class="p"&gt;;&lt;/span&gt;
  cursor: pointer&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Form:
&lt;/h3&gt;

&lt;p&gt;This class is used to style a form element on a web page. &lt;/p&gt;

&lt;p&gt;It is typically used to set the width, background color, and padding of the form.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;.form &lt;span class="o"&gt;{&lt;/span&gt;
  width: 100%&lt;span class="p"&gt;;&lt;/span&gt;
  background-color: &lt;span class="c"&gt;#f1f1f1;&lt;/span&gt;
  padding: 20px&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Card:
&lt;/h3&gt;

&lt;p&gt;This class is used to create a card element on a web page. &lt;/p&gt;

&lt;p&gt;It is typically used to group related content together and apply styling to the card as a whole.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;.card &lt;span class="o"&gt;{&lt;/span&gt;
  background-color: &lt;span class="c"&gt;#fff;&lt;/span&gt;
  border: 1px solid &lt;span class="c"&gt;#ccc;&lt;/span&gt;
  border-radius: 5px&lt;span class="p"&gt;;&lt;/span&gt;
  box-shadow: 0 0 5px rgba&lt;span class="o"&gt;(&lt;/span&gt;0, 0, 0, 0.1&lt;span class="o"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  padding: 20px&lt;span class="p"&gt;;&lt;/span&gt;
  margin: 20px&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we've set the background color of the card to white, added a 1-pixel solid border with a light gray color, and set the border radius to 5 pixels to give the card rounded corners. &lt;/p&gt;

&lt;p&gt;We've also added a box shadow to give the card a slight drop shadow effect. &lt;/p&gt;

&lt;p&gt;Finally, we've added padding and margin to create space between the content of the card and other elements on the page.&lt;/p&gt;

&lt;p&gt;To use the "card" class in HTML, you would simply add the "card" class to a div element that contains the content you want to display in the card. &lt;/p&gt;

&lt;p&gt;Here's an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&amp;lt;div &lt;span class="nv"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"card"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
  &amp;lt;h2&amp;gt;Card Title&amp;lt;/h2&amp;gt;
  &amp;lt;p&amp;gt;This is some example content &lt;span class="k"&gt;for &lt;/span&gt;the card.&amp;lt;/p&amp;gt;
  &amp;lt;button&amp;gt;Click me&amp;lt;/button&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we've created a div element with the "card" class and added a heading, paragraph, and button element inside it. &lt;/p&gt;

&lt;p&gt;When we view the page in a web browser, the content will be displayed inside a card with the styling we defined in the CSS.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Common CSS syling classes
&lt;/h2&gt;

&lt;p&gt;CSS styling classes are used to apply a particular style or effect to an HTML element. &lt;/p&gt;

&lt;p&gt;Here are some commonly used CSS styling classes:&lt;/p&gt;

&lt;h3&gt;
  
  
  Text styles:
&lt;/h3&gt;

&lt;p&gt;These classes are used to define the font size, font weight, font family, color, and text alignment of text content.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;.text-center &lt;span class="o"&gt;{&lt;/span&gt;
  text-align: center&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

.text-bold &lt;span class="o"&gt;{&lt;/span&gt;
  font-weight: bold&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

.text-large &lt;span class="o"&gt;{&lt;/span&gt;
  font-size: 24px&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

.text-serif &lt;span class="o"&gt;{&lt;/span&gt;
  font-family: serif&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

.text-muted &lt;span class="o"&gt;{&lt;/span&gt;
  color: &lt;span class="c"&gt;#999;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Background and color:
&lt;/h3&gt;

&lt;p&gt;These classes are used to define the background color and text color of an HTML element.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;.bg-primary &lt;span class="o"&gt;{&lt;/span&gt;
  background-color: &lt;span class="c"&gt;#007bff;&lt;/span&gt;
  color: &lt;span class="c"&gt;#fff;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

.bg-secondary &lt;span class="o"&gt;{&lt;/span&gt;
  background-color: &lt;span class="c"&gt;#6c757d;&lt;/span&gt;
  color: &lt;span class="c"&gt;#fff;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

.bg-light &lt;span class="o"&gt;{&lt;/span&gt;
  background-color: &lt;span class="c"&gt;#f8f9fa;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

.bg-dark &lt;span class="o"&gt;{&lt;/span&gt;
  background-color: &lt;span class="c"&gt;#343a40;&lt;/span&gt;
  color: &lt;span class="c"&gt;#fff;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Borders:
&lt;/h3&gt;

&lt;p&gt;These classes are used to define the border style, width, color, and radius of an HTML element.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;.border &lt;span class="o"&gt;{&lt;/span&gt;
  border: 1px solid &lt;span class="c"&gt;#ccc;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

.border-top &lt;span class="o"&gt;{&lt;/span&gt;
  border-top: 1px solid &lt;span class="c"&gt;#ccc;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

.border-radius &lt;span class="o"&gt;{&lt;/span&gt;
  border-radius: 5px&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Padding and margin:
&lt;/h3&gt;

&lt;p&gt;These classes are used to define the padding and margin of an HTML element.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;.p-4 &lt;span class="o"&gt;{&lt;/span&gt;
  padding: 16px&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

.m-4 &lt;span class="o"&gt;{&lt;/span&gt;
  margin: 16px&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Display and positioning:
&lt;/h3&gt;

&lt;p&gt;These classes are used to control the display and positioning of an HTML element.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;.d-flex &lt;span class="o"&gt;{&lt;/span&gt;
  display: flex&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

.d-inline-block &lt;span class="o"&gt;{&lt;/span&gt;
  display: inline-block&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

.position-relative &lt;span class="o"&gt;{&lt;/span&gt;
  position: relative&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

.position-absolute &lt;span class="o"&gt;{&lt;/span&gt;
  position: absolute&lt;span class="p"&gt;;&lt;/span&gt;
  top: 0&lt;span class="p"&gt;;&lt;/span&gt;
  right: 0&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Hover and active states:
&lt;/h3&gt;

&lt;p&gt;These classes are used to apply styles to an HTML element when the user hovers over or clicks on it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;.hover-bg-primary:hover &lt;span class="o"&gt;{&lt;/span&gt;
  background-color: &lt;span class="c"&gt;#007bff;&lt;/span&gt;
  color: &lt;span class="c"&gt;#fff;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

.active-bg-primary:active &lt;span class="o"&gt;{&lt;/span&gt;
  background-color: &lt;span class="c"&gt;#0062cc;&lt;/span&gt;
  color: &lt;span class="c"&gt;#fff;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These are just a few examples of the many CSS styling classes available. &lt;/p&gt;

&lt;p&gt;By combining these classes and customizing their properties, you can create a wide range of styles and effects for your web pages.&lt;/p&gt;

&lt;h2&gt;
  
  
  6. CSS Specificity
&lt;/h2&gt;

&lt;p&gt;CSS specificity is a measure of how specific a selector is in targeting a particular HTML element. &lt;/p&gt;

&lt;p&gt;It determines which styles are applied to an element when there are conflicting styles defined in different stylesheets or within the same stylesheet.&lt;/p&gt;

&lt;p&gt;CSS selectors have different levels of specificity based on the elements, classes, and IDs that they target. &lt;/p&gt;

&lt;p&gt;Here's a breakdown of how specificity is calculated:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Element selectors have the lowest specificity and are worth 1 point.&lt;/li&gt;
&lt;li&gt;Class selectors are worth 10 points.&lt;/li&gt;
&lt;li&gt;ID selectors are worth 100 points.&lt;/li&gt;
&lt;li&gt;Inline styles have the highest specificity and are worth 1000 points.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When multiple selectors target the same element, the selector with the highest specificity is applied. &lt;/p&gt;

&lt;p&gt;For example, if you have the following CSS:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;p &lt;span class="o"&gt;{&lt;/span&gt;
  color: red&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;#paragraph {&lt;/span&gt;
  color: blue&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And this HTML:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&amp;lt;p &lt;span class="nb"&gt;id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"paragraph"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;This is a paragraph.&amp;lt;/p&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The color of the text will be blue because the ID selector for "#paragraph" has a higher specificity than the element selector for "p".&lt;/p&gt;

&lt;p&gt;If multiple selectors have the same specificity, the one that appears last in the CSS document takes precedence. &lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;p &lt;span class="o"&gt;{&lt;/span&gt;
  color: red&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;span class="c"&gt;#paragraph {&lt;/span&gt;
  color: blue&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

p &lt;span class="o"&gt;{&lt;/span&gt;
  font-size: 24px&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this case, the color of the text will be blue and the font size will be 24px because the second "p" selector overrides the font size defined by the first "p" selector.&lt;/p&gt;

&lt;p&gt;It's important to be aware of CSS specificity when writing stylesheets to ensure that the correct styles are applied to your HTML elements. &lt;/p&gt;

&lt;p&gt;In general, it's best to use the least specific selectors possible to target elements, and to avoid using inline styles whenever possible.&lt;/p&gt;

&lt;h2&gt;
  
  
  7. CSS Responsive Queries
&lt;/h2&gt;

&lt;p&gt;CSS responsive queries are used to create styles that adapt to different screen sizes and devices, allowing your web pages to look good on a variety of devices such as desktops, laptops, tablets, and smartphones.&lt;/p&gt;

&lt;p&gt;There are several ways to create responsive designs using CSS, but the most common technique is using media queries.&lt;/p&gt;

&lt;p&gt;Media queries allow you to define different styles for different screen sizes and resolutions. &lt;/p&gt;

&lt;p&gt;Here's an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;/&lt;span class="k"&gt;*&lt;/span&gt; Styles &lt;span class="k"&gt;for &lt;/span&gt;screens smaller than 768px &lt;span class="k"&gt;*&lt;/span&gt;/
@media &lt;span class="o"&gt;(&lt;/span&gt;max-width: 767px&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
  .container &lt;span class="o"&gt;{&lt;/span&gt;
    width: 100%&lt;span class="p"&gt;;&lt;/span&gt;
    padding: 20px&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="o"&gt;}&lt;/span&gt;
  .heading &lt;span class="o"&gt;{&lt;/span&gt;
    font-size: 24px&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;

/&lt;span class="k"&gt;*&lt;/span&gt; Styles &lt;span class="k"&gt;for &lt;/span&gt;screens larger than 768px &lt;span class="k"&gt;*&lt;/span&gt;/
@media &lt;span class="o"&gt;(&lt;/span&gt;min-width: 768px&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
  .container &lt;span class="o"&gt;{&lt;/span&gt;
    width: 700px&lt;span class="p"&gt;;&lt;/span&gt;
    margin: 0 auto&lt;span class="p"&gt;;&lt;/span&gt;
    padding: 40px&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="o"&gt;}&lt;/span&gt;
  .heading &lt;span class="o"&gt;{&lt;/span&gt;
    font-size: 36px&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="o"&gt;}&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we have defined two media queries. &lt;/p&gt;

&lt;p&gt;The first query targets screens smaller than 768px and applies styles to the "container" and "heading" elements to make them more readable on small screens. &lt;/p&gt;

&lt;p&gt;The second query targets screens larger than 768px and applies different styles to the same elements to make them look better on larger screens.&lt;/p&gt;

&lt;p&gt;Media queries can be based on a variety of factors such as screen size, resolution, device orientation, and more. &lt;/p&gt;

&lt;p&gt;Here are some common media query options:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;max-width&lt;/strong&gt;: &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Sets the maximum width of the screen.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;min-width&lt;/strong&gt;: &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Sets the minimum width of the screen.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;orientation&lt;/strong&gt;: &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Sets the device orientation to portrait or landscape.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;max-device-width&lt;/strong&gt;: &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Sets the maximum width of the device screen.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;min-device-width&lt;/strong&gt;: &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Sets the minimum width of the device screen.&lt;/p&gt;

&lt;p&gt;By using media queries in your CSS, you can create responsive designs that look good on any device. &lt;/p&gt;

&lt;p&gt;However, it's important to test your styles on a variety of devices to ensure that they work as expected.&lt;/p&gt;

&lt;h2&gt;
  
  
  8. Flexbox/Grid
&lt;/h2&gt;

&lt;p&gt;Flexbox and CSS Grid are two popular CSS layout systems used to create responsive and flexible designs. &lt;/p&gt;

&lt;p&gt;Here's a brief overview of each:&lt;/p&gt;

&lt;h3&gt;
  
  
  Flexbox:
&lt;/h3&gt;

&lt;p&gt;Flexbox is a one-dimensional layout system that is designed to make it easier to create flexible and responsive layouts. &lt;/p&gt;

&lt;p&gt;It allows you to align and distribute content within a container in a flexible way. &lt;/p&gt;

&lt;p&gt;Flexbox works by creating a flexible container that can hold a set of flexible items. &lt;/p&gt;

&lt;p&gt;You can define the size, order, and alignment of these items using various properties such as display, flex-direction, justify-content, align-items, and flex-wrap.&lt;/p&gt;

&lt;h3&gt;
  
  
  CSS Grid:
&lt;/h3&gt;

&lt;p&gt;CSS Grid is a two-dimensional layout system that is designed to create complex grid layouts that are responsive and flexible. &lt;br&gt;
It allows you to define rows and columns in a grid and place content in specific areas within the grid. &lt;/p&gt;

&lt;p&gt;CSS Grid works by creating a container that is divided into a set of rows and columns. &lt;/p&gt;

&lt;p&gt;You can define the size and position of these rows and columns using various properties such as grid-template-rows, grid-template-columns, grid-row-start, grid-column-end, and grid-gap.&lt;/p&gt;

&lt;p&gt;Flexbox is best suited for creating one-dimensional layouts such as navigation menus, card layouts, and form layouts.&lt;/p&gt;

&lt;p&gt;CSS Grid is best suited for creating complex two-dimensional layouts such as magazine-style layouts, image galleries, and dashboard layouts. &lt;/p&gt;

&lt;p&gt;However, both Flexbox and CSS Grid can be used together to create more complex and flexible layouts.&lt;/p&gt;

&lt;p&gt;Overall, Flexbox and CSS Grid are both powerful layout systems that can help you create responsive and flexible designs. &lt;/p&gt;

&lt;p&gt;It's important to choose the right layout system based on your specific needs and to use them appropriately to achieve the desired layout.&lt;/p&gt;
&lt;h2&gt;
  
  
  9. Common header meta tags
&lt;/h2&gt;

&lt;p&gt;Header meta tags are an important part of a web page's HTML code that provide information about the page's content to search engines, social media platforms, and other web services. &lt;/p&gt;

&lt;p&gt;Here are some of the most common header meta tags and their purposes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&amp;lt;meta &lt;span class="nv"&gt;charset&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"UTF-8"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Specifies the character encoding used by the page. UTF-8 is the most widely used character encoding and supports all Unicode characters.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&amp;lt;meta &lt;span class="nv"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"viewport"&lt;/span&gt; &lt;span class="nv"&gt;content&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"width=device-width, initial-scale=1.0"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Specifies the viewport settings for mobile devices, which affects the layout and scaling of the page on different devices. &lt;/p&gt;

&lt;p&gt;This tag tells the browser to use the width of the device as the width of the viewport, and to set the initial zoom level to 1.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&amp;lt;title&amp;gt;Page Title&amp;lt;/title&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Specifies the title of the page, which appears in the browser's title bar and is used by search engines as the title of the search result.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&amp;lt;meta &lt;span class="nv"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"description"&lt;/span&gt; &lt;span class="nv"&gt;content&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"Page description"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Specifies a brief description of the page's content, which appears in search results and is used by search engines to understand the page's content.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&amp;lt;meta &lt;span class="nv"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"keywords"&lt;/span&gt; &lt;span class="nv"&gt;content&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"keyword1, keyword2, keyword3"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Specifies a comma-separated list of keywords that describe the page's content, which can help search engines understand the page's topic and improve its ranking.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&amp;lt;meta &lt;span class="nv"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"robots"&lt;/span&gt; &lt;span class="nv"&gt;content&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"index, follow"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Specifies whether search engines should index the page and follow its links. &lt;/p&gt;

&lt;p&gt;By default, search engines will index and follow all pages.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&amp;lt;&lt;span class="nb"&gt;link &lt;/span&gt;&lt;span class="nv"&gt;rel&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"canonical"&lt;/span&gt; &lt;span class="nv"&gt;href&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"https://www.example.com/"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Specifies the canonical URL of the page, which is the preferred URL that search engines should use to index the page. &lt;/p&gt;

&lt;p&gt;This is useful when there are multiple URLs that can access the same content.&lt;/p&gt;

&lt;h2&gt;
  
  
  10. Open Graph Tags
&lt;/h2&gt;

&lt;p&gt;Open Graph tags are meta tags that are used to provide social media platforms and search engines with information about a web page. &lt;/p&gt;

&lt;p&gt;They are used to specify the title, description, and image to be used when a page is shared on social media or displayed in search results. &lt;/p&gt;

&lt;p&gt;Here are some examples of Open Graph tags :&lt;/p&gt;

&lt;h3&gt;
  
  
  Title Tag:
&lt;/h3&gt;

&lt;p&gt;The title tag specifies the title of the page, which is displayed in search results and on social media platforms.&lt;/p&gt;

&lt;p&gt;Here's an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&amp;lt;&lt;span class="nb"&gt;head&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
  &amp;lt;title&amp;gt;My Website Title&amp;lt;/title&amp;gt;
  &amp;lt;meta &lt;span class="nv"&gt;property&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"og:title"&lt;/span&gt; &lt;span class="nv"&gt;content&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"My Website Title"&lt;/span&gt;/&amp;gt;
&amp;lt;/head&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Description Tag:
&lt;/h3&gt;

&lt;p&gt;The description tag provides a summary of the page's content and is displayed in search results and on social media platforms. &lt;/p&gt;

&lt;p&gt;Here's an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&amp;lt;&lt;span class="nb"&gt;head&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
  &amp;lt;meta &lt;span class="nv"&gt;name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"description"&lt;/span&gt; &lt;span class="nv"&gt;content&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"A description of my website."&lt;/span&gt;/&amp;gt;
  &amp;lt;meta &lt;span class="nv"&gt;property&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"og:description"&lt;/span&gt; &lt;span class="nv"&gt;content&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"A description of my website."&lt;/span&gt;/&amp;gt;
&amp;lt;/head&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Image Tag:
&lt;/h3&gt;

&lt;p&gt;The image tag specifies the image to be displayed when the page is shared on social media platforms. &lt;/p&gt;

&lt;p&gt;Here's an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&amp;lt;&lt;span class="nb"&gt;head&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
  &amp;lt;meta &lt;span class="nv"&gt;property&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"og:image"&lt;/span&gt; &lt;span class="nv"&gt;content&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"https://example.com/image.jpg"&lt;/span&gt;/&amp;gt;
&amp;lt;/head&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  URL Tag:
&lt;/h3&gt;

&lt;p&gt;The URL tag specifies the URL of the page, which is displayed in search results and on social media platforms. &lt;/p&gt;

&lt;p&gt;Here's an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&amp;lt;&lt;span class="nb"&gt;head&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
  &amp;lt;&lt;span class="nb"&gt;link &lt;/span&gt;&lt;span class="nv"&gt;rel&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"canonical"&lt;/span&gt; &lt;span class="nv"&gt;href&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"https://example.com"&lt;/span&gt;/&amp;gt;
  &amp;lt;meta &lt;span class="nv"&gt;property&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"og:url"&lt;/span&gt; &lt;span class="nv"&gt;content&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"https://example.com"&lt;/span&gt;/&amp;gt;
&amp;lt;/head&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note that these Open Graph tags are typically placed in the head section of the HTML document, but they can also be included in CSS files using the @import rule. &lt;/p&gt;

&lt;p&gt;However, it's not recommended to include them in CSS files as it can cause problems with some social media platforms.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In conclusion, understanding the Box Model is essential to creating a well-structured webpage. &lt;/p&gt;

&lt;p&gt;Inline and Block elements offer different styling options and should be chosen accordingly. &lt;/p&gt;

&lt;p&gt;Positioning, both Relative and Absolute, are useful tools to create dynamic layouts. &lt;/p&gt;

&lt;p&gt;CSS Specificity determines how styles are applied and should be used with caution. &lt;/p&gt;

&lt;p&gt;CSS Responsive Queries allow websites to adapt to different screen sizes and devices. &lt;/p&gt;

&lt;p&gt;Flexbox and Grid are powerful tools for creating complex layouts. &lt;/p&gt;

&lt;p&gt;Lastly, using common header meta tags and Open Graph tags can enhance a website's social media presence and search engine visibility. &lt;/p&gt;

&lt;p&gt;By utilizing these CSS techniques and best practices, you can create a visually appealing and engaging website that works across multiple platforms and devices.&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;p&gt;Box Model:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.w3schools.com/css/css_boxmodel.asp"&gt;https://www.w3schools.com/css/css_boxmodel.asp&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Inline versus Block Elements:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://css-tricks.com/when-do-you-use-inline-block/"&gt;https://css-tricks.com/when-do-you-use-inline-block/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Positioning: Relative/Absolute:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/position"&gt;https://developer.mozilla.org/en-US/docs/Web/CSS/position&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Common CSS Structural Classes:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/container"&gt;https://developer.mozilla.org/en-US/docs/Web/CSS/container&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Common CSS Styling Classes:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://css-tricks.com/almanac/"&gt;https://css-tricks.com/almanac/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;CSS Specificity:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://specificity.keegan.st/"&gt;https://specificity.keegan.st/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;CSS Responsive Queries:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.w3schools.com/css/css_rwd_mediaqueries.asp"&gt;https://www.w3schools.com/css/css_rwd_mediaqueries.asp&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Flexbox/Grid:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://css-tricks.com/snippets/css/a-guide-to-flexbox/"&gt;https://css-tricks.com/snippets/css/a-guide-to-flexbox/&lt;/a&gt;&lt;br&gt;
&lt;a href="https://css-tricks.com/snippets/css/complete-guide-grid/"&gt;https://css-tricks.com/snippets/css/complete-guide-grid/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Common Header Meta Tags:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.w3schools.com/tags/tag_head.asp"&gt;https://www.w3schools.com/tags/tag_head.asp&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Open Graph Tags:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://ogp.me/"&gt;https://ogp.me/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>html</category>
      <category>css</category>
      <category>webdev</category>
    </item>
    <item>
      <title>SQL Concepts</title>
      <dc:creator>Manisha Kundrapu</dc:creator>
      <pubDate>Tue, 21 Feb 2023 06:58:58 +0000</pubDate>
      <link>https://dev.to/manishakundrapu/sql-concepts-1hdf</link>
      <guid>https://dev.to/manishakundrapu/sql-concepts-1hdf</guid>
      <description>&lt;p&gt;The following are some of the concepts that are included to understand databases:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;ACID&lt;/li&gt;
&lt;li&gt;CAP Theorem&lt;/li&gt;
&lt;li&gt;Joins&lt;/li&gt;
&lt;li&gt;Aggregations and Filters in Queries&lt;/li&gt;
&lt;li&gt;Normalization&lt;/li&gt;
&lt;li&gt;Indexes&lt;/li&gt;
&lt;li&gt;Transactions&lt;/li&gt;
&lt;li&gt;Locking Mechanism&lt;/li&gt;
&lt;li&gt;Database Isolation Levels&lt;/li&gt;
&lt;li&gt;Triggers&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  ACID
&lt;/h2&gt;

&lt;p&gt;ACID is an acronym that stands for Atomicity, Consistency, Isolation, and Durability. &lt;/p&gt;

&lt;p&gt;These are the key properties of a database transaction that ensure data integrity and reliability.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Atomicity:
&lt;/h3&gt;

&lt;p&gt;Atomicity guarantees that a transaction is treated as a single, indivisible unit of work that either completes in its entirety or is rolled back (undone) completely in the event of any failure or error.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;: &lt;/p&gt;

&lt;p&gt;A bank transfer that involves deducting money from one account and adding it to another account is an example of an atomic transaction. If either the debit or credit transaction fails, both transactions should be rolled back to ensure data consistency.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Consistency:
&lt;/h3&gt;

&lt;p&gt;Consistency ensures that a transaction takes the database from one valid state to another valid state. It ensures that the database is consistent both before and after the transaction.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;: &lt;/p&gt;

&lt;p&gt;If a transaction involves adding a new record to a database, it should ensure that the record meets all the constraints and rules set forth by the database schema before being added.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Isolation:
&lt;/h3&gt;

&lt;p&gt;Isolation ensures that each transaction is executed independently of any other transaction, without interference or dependence on any other transaction occurring simultaneously.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;: &lt;/p&gt;

&lt;p&gt;If two transactions occur simultaneously, one transaction should not be able to access the data modified by another transaction until the transaction is completed and the data is committed to the database.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Durability:
&lt;/h3&gt;

&lt;p&gt;Durability ensures that once a transaction is committed to the database, it will remain there permanently, even in the event of power failures, crashes, or other system failures.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;: &lt;/p&gt;

&lt;p&gt;If a database crashes after a transaction has been committed, the data from that transaction will still be available when the database is restored.&lt;/p&gt;

&lt;p&gt;Overall, ACID provides a set of principles to ensure that database transactions are reliable, consistent, and accurate, making it an essential concept for building robust and scalable database systems.&lt;/p&gt;

&lt;h2&gt;
  
  
  CAP Theorem
&lt;/h2&gt;

&lt;p&gt;The CAP theorem, also known as Brewer's theorem, is a fundamental concept in distributed database systems that describes the tradeoffs that must be made when building highly available and fault-tolerant systems.&lt;/p&gt;

&lt;p&gt;The theorem states that in a distributed database system, you can only have two out of the following three guarantees.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Consistency:
&lt;/h3&gt;

&lt;p&gt;All nodes in the system see the same data at the same time, regardless of which node receives the update request.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Availability:
&lt;/h3&gt;

&lt;p&gt;Every request made to the system receives a response, without guarantee that it contains the most recent version of the information.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Partition tolerance:
&lt;/h3&gt;

&lt;p&gt;The system continues to operate despite arbitrary message loss or failure of part of the system.&lt;/p&gt;

&lt;p&gt;In practical terms, this means that when building a distributed database system, you must choose which two of these guarantees are most important for your application and optimize the system accordingly.&lt;/p&gt;

&lt;p&gt;For example, consider an e-commerce website that relies on a distributed database to manage inventory and process transactions. In this scenario, consistency and availability are the two most important guarantees, as it is critical that the website always has accurate inventory information and can process transactions in a timely manner. Partition tolerance may be less important, as the website can temporarily go offline if there is a network issue or a node failure.&lt;/p&gt;

&lt;p&gt;On the other hand, consider a social media platform where users are frequently posting updates, and the priority is to ensure that all updates are eventually replicated across all nodes in the system, even in the event of network partitions. In this scenario, partition tolerance and consistency are the two most important guarantees, while availability may be less critical.&lt;/p&gt;

&lt;p&gt;Overall, the CAP theorem highlights the fundamental tradeoffs that must be made when building distributed database systems, and emphasizes the importance of choosing the appropriate tradeoffs based on the requirements of your specific application.&lt;/p&gt;

&lt;h2&gt;
  
  
  Joins
&lt;/h2&gt;

&lt;p&gt;In SQL, a join is a way to combine data from two or more tables into a single result set based on a common column. There are several types of joins, including:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Inner join:
&lt;/h3&gt;

&lt;p&gt;Returns only the rows that have matching values in both tables.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;: &lt;/p&gt;

&lt;p&gt;Suppose you have two tables - "orders" and "customers". To get a list of all orders along with the customer name, you can use an inner join on the "customer_id" column.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;SELECT orders.order_id, customers.customer_name
FROM orders
INNER JOIN customers
ON orders.customer_id &lt;span class="o"&gt;=&lt;/span&gt; customers.customer_id&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. Left join:
&lt;/h3&gt;

&lt;p&gt;Returns all rows from the left table and matching rows from the right table. If there are no matching rows in the right table, the result will contain NULL values for the right table columns.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;: &lt;/p&gt;

&lt;p&gt;Suppose you have two tables - "customers" and "orders". To get a list of all customers and their orders (if any), you can use a left join on the "customer_id" column.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;SELECT customers.customer_name, orders.order_id
FROM customers
LEFT JOIN orders
ON customers.customer_id &lt;span class="o"&gt;=&lt;/span&gt; orders.customer_id&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3. Right join:
&lt;/h3&gt;

&lt;p&gt;Returns all rows from the right table and matching rows from the left table. If there are no matching rows in the left table, the result will contain NULL values for the left table columns.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;: &lt;/p&gt;

&lt;p&gt;Suppose you have two tables - "orders" and "customers". To get a list of all orders and the customer name (if available), you can use a right join on the "customer_id" column.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;SELECT orders.order_id, customers.customer_name
FROM orders
RIGHT JOIN customers
ON orders.customer_id &lt;span class="o"&gt;=&lt;/span&gt; customers.customer_id&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  4. Full outer join:
&lt;/h3&gt;

&lt;p&gt;Returns all rows from both tables, with NULL values in the columns where there are no matches.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;: &lt;/p&gt;

&lt;p&gt;Suppose you have two tables - "customers" and "orders". To get a list of all customers and all orders, you can use a full outer join on the "customer_id" column.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;SELECT customers.customer_name, orders.order_id
FROM customers
FULL OUTER JOIN orders
ON customers.customer_id &lt;span class="o"&gt;=&lt;/span&gt; orders.customer_id&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Joins are a powerful tool for combining data from multiple tables in SQL, and can be used in a variety of scenarios to retrieve useful information from a database.&lt;/p&gt;

&lt;h2&gt;
  
  
  Aggregations, Filters in queries
&lt;/h2&gt;

&lt;p&gt;In SQL, aggregations and filters are powerful tools for querying and summarizing large datasets.&lt;/p&gt;

&lt;p&gt;Aggregations are used to calculate summary statistics, such as averages, sums, counts, and maximum or minimum values, on one or more columns of data. The most commonly used aggregation functions in SQL include:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. COUNT:
&lt;/h3&gt;

&lt;p&gt;Returns the number of rows in a table or the number of rows that match a specified condition.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;: &lt;/p&gt;

&lt;p&gt;To count the number of orders in a table called "orders", you can use the following query:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;SELECT COUNT&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="k"&gt;*&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
FROM orders&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. SUM:
&lt;/h3&gt;

&lt;p&gt;Returns the sum of the values in a specified column.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;: &lt;/p&gt;

&lt;p&gt;To calculate the total revenue from a table called "sales", you can use the following query:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;SELECT SUM&lt;span class="o"&gt;(&lt;/span&gt;revenue&lt;span class="o"&gt;)&lt;/span&gt;
FROM sales&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3. AVG:
&lt;/h3&gt;

&lt;p&gt;Returns the average value of the values in a specified column.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;: &lt;/p&gt;

&lt;p&gt;To calculate the average price of a product from a table called "products", you can use the following query:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;SELECT AVG&lt;span class="o"&gt;(&lt;/span&gt;price&lt;span class="o"&gt;)&lt;/span&gt;
FROM products&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Filters, on the other hand, are used to retrieve specific subsets of data from a table based on specified conditions.&lt;/p&gt;

&lt;p&gt;The most commonly used filter clauses in SQL include:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. WHERE:
&lt;/h3&gt;

&lt;p&gt;Filters the data based on a specified condition.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;: &lt;/p&gt;

&lt;p&gt;To retrieve all orders with a total value greater than $1000 from a table called "orders", you can use the following query.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;SELECT &lt;span class="k"&gt;*&lt;/span&gt;
FROM orders
WHERE total_value &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; 1000&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. GROUP BY:
&lt;/h3&gt;

&lt;p&gt;Groups the data based on one or more columns, and allows for aggregations to be calculated for each group.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;: &lt;/p&gt;

&lt;p&gt;To calculate the total revenue for each region from a table called "sales", you can use the following query:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;SELECT region, SUM&lt;span class="o"&gt;(&lt;/span&gt;revenue&lt;span class="o"&gt;)&lt;/span&gt;
FROM sales
GROUP BY region&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3. HAVING:
&lt;/h3&gt;

&lt;p&gt;Filters the results of a GROUP BY clause based on a specified condition.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;: &lt;/p&gt;

&lt;p&gt;To retrieve all regions with a total revenue greater than $100,000 from a table called "sales", you can use the following query.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;SELECT region, SUM&lt;span class="o"&gt;(&lt;/span&gt;revenue&lt;span class="o"&gt;)&lt;/span&gt;
FROM sales
GROUP BY region
HAVING SUM&lt;span class="o"&gt;(&lt;/span&gt;revenue&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; 100000&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Aggregations and filters are two essential tools for working with large datasets in SQL, and can be used together to generate powerful insights and reports.&lt;/p&gt;

&lt;h2&gt;
  
  
  Normalization
&lt;/h2&gt;

&lt;p&gt;Normalization is a process of organizing data in a database to reduce redundancy and improve data integrity. &lt;/p&gt;

&lt;p&gt;It involves breaking down a table into smaller tables and establishing relationships between them to eliminate data duplication and inconsistencies.&lt;/p&gt;

&lt;p&gt;There are different levels of normalization, also known as normal forms. &lt;/p&gt;

&lt;p&gt;The most commonly used are:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. First Normal Form (1NF):
&lt;/h3&gt;

&lt;p&gt;A table is in 1NF if it has no repeating groups or arrays. Each column in the table must contain atomic (indivisible) values. &lt;/p&gt;

&lt;p&gt;For example, a table with a column for phone numbers should not store multiple phone numbers in a single field separated by commas.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Second Normal Form (2NF):
&lt;/h3&gt;

&lt;p&gt;A table is in 2NF if it is in 1NF and all non-key columns are dependent on the entire primary key. In other words, all columns in a table must be related to the primary key, and not just a part of it. &lt;/p&gt;

&lt;p&gt;For example, a table with customer orders should have separate tables for customers and orders, with the order table referencing the customer table through a foreign key.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Third Normal Form (3NF):
&lt;/h3&gt;

&lt;p&gt;A table is in 3NF if it is in 2NF and has no transitive dependencies. In other words, all non-key columns in a table must be related only to the primary key, and not to other non-key columns. &lt;/p&gt;

&lt;p&gt;For example, a table with information about customers and their orders should not have a column for the salesperson who made the sale, as this information is not directly related to the customer or the order.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;Consider a table called "Customer_Order" with the following columns.&lt;/p&gt;

&lt;p&gt;Customer_ID&lt;br&gt;
Customer_Name&lt;br&gt;
Customer_Phone&lt;br&gt;
Order_ID&lt;br&gt;
Order_Date&lt;br&gt;
Order_Amount&lt;/p&gt;

&lt;p&gt;This table is not normalized as it contains repeating groups (phone numbers) and has transitive dependencies (order amount is dependent on order ID and not directly on customer ID). To normalize this table, we can create two separate tables as follows.&lt;/p&gt;

&lt;p&gt;Customer table:&lt;/p&gt;

&lt;p&gt;Customer_ID (Primary Key)&lt;br&gt;
Customer_Name&lt;br&gt;
Customer_Phone&lt;br&gt;
Order table:&lt;/p&gt;

&lt;p&gt;Order_ID (Primary Key)&lt;br&gt;
Order_Date&lt;br&gt;
Order_Amount&lt;br&gt;
Customer_ID (Foreign Key)&lt;/p&gt;

&lt;p&gt;By breaking down the original table into two smaller tables, we have eliminated redundancy and established a relationship between the customer and order tables through the customer ID and order ID columns. &lt;/p&gt;

&lt;p&gt;This ensures data consistency and reduces the likelihood of errors in the database.&lt;/p&gt;
&lt;h2&gt;
  
  
  Indexes
&lt;/h2&gt;

&lt;p&gt;Indexes in SQL are used to improve the performance of queries by allowing faster data retrieval. &lt;/p&gt;

&lt;p&gt;An index is a data structure that contains a copy of selected columns of a table arranged in a specific order that enables faster lookups, sorting, and filtering.&lt;/p&gt;

&lt;p&gt;When a query is executed, the database engine uses the index to locate the data more quickly, rather than scanning the entire table. &lt;/p&gt;

&lt;p&gt;Indexes are typically created on columns that are frequently used in queries, such as primary keys or columns used in WHERE clauses.&lt;/p&gt;

&lt;p&gt;There are several types of indexes available in SQL, including:&lt;/p&gt;
&lt;h3&gt;
  
  
  1. Clustered index:
&lt;/h3&gt;

&lt;p&gt;A clustered index determines the physical order of the rows in a table based on the values in one or more columns. Each table can have only one clustered index.&lt;/p&gt;
&lt;h3&gt;
  
  
  2. Non-clustered index:
&lt;/h3&gt;

&lt;p&gt;A non-clustered index creates a separate data structure that contains the index key values and a pointer to the location of the actual data. Multiple non-clustered indexes can be created on a table.&lt;/p&gt;
&lt;h3&gt;
  
  
  3. Unique index:
&lt;/h3&gt;

&lt;p&gt;A unique index ensures that the values in a column or combination of columns are unique. Each table can have multiple unique indexes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;Consider a table called "Employee" with the following columns.&lt;/p&gt;

&lt;p&gt;Employee_ID (Primary Key)&lt;br&gt;
Employee_Name&lt;br&gt;
Employee_Age&lt;br&gt;
Employee_Salary&lt;/p&gt;

&lt;p&gt;To improve the performance of queries that frequently use the Employee_Name column, we can create a non-clustered index on that column as follows.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;CREATE NONCLUSTERED INDEX ix_Employee_Name ON Employee &lt;span class="o"&gt;(&lt;/span&gt;Employee_Name&lt;span class="o"&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This index creates a separate data structure containing the Employee_Name column and a pointer to the location of the actual data in the Employee table. When a query includes the Employee_Name column in a WHERE clause, the database engine can use the index to quickly locate the relevant rows in the table.&lt;/p&gt;

&lt;p&gt;In addition, we can create a unique index on the Employee_ID column to ensure that each employee has a unique identifier:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;CREATE UNIQUE INDEX ix_Employee_ID ON Employee &lt;span class="o"&gt;(&lt;/span&gt;Employee_ID&lt;span class="o"&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This index prevents duplicate values in the Employee_ID column, ensuring data integrity and efficient data retrieval for queries that use the Employee_ID column.&lt;/p&gt;

&lt;h2&gt;
  
  
  Transactions
&lt;/h2&gt;

&lt;p&gt;In SQL, a transaction is a sequence of database operations that are executed as a single unit of work. &lt;/p&gt;

&lt;p&gt;A transaction ensures that all the operations within it are completed successfully, or none of them are, so that the database remains in a consistent state.&lt;/p&gt;

&lt;p&gt;Transactions typically include multiple SQL statements, such as SELECT, INSERT, UPDATE, and DELETE, and they are used to ensure data integrity and consistency. &lt;/p&gt;

&lt;p&gt;If any part of a transaction fails, the database will automatically roll back all the changes made during the transaction to ensure that the database remains consistent.&lt;/p&gt;

&lt;p&gt;To ensure that a sequence of SQL statements is executed as a transaction, we use the following commands:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;BEGIN TRANSACTION: Starts a new transaction.&lt;/li&gt;
&lt;li&gt;COMMIT: Ends a transaction and saves all the changes made during it.&lt;/li&gt;
&lt;li&gt;ROLLBACK: Ends a transaction and undoes all the changes made during it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;Consider a table called "Bank_Account" with the following columns:&lt;/p&gt;

&lt;p&gt;Account_ID (Primary Key)&lt;br&gt;
Account_Balance&lt;/p&gt;

&lt;p&gt;To transfer funds from one account to another, we can use a transaction to ensure that the transfer is completed successfully, or none of it is. The transaction can be implemented using the following SQL statements.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;BEGIN TRANSACTION
UPDATE Bank_Account SET Account_Balance &lt;span class="o"&gt;=&lt;/span&gt; Account_Balance - 500 WHERE Account_ID &lt;span class="o"&gt;=&lt;/span&gt; 12345
UPDATE Bank_Account SET Account_Balance &lt;span class="o"&gt;=&lt;/span&gt; Account_Balance + 500 WHERE Account_ID &lt;span class="o"&gt;=&lt;/span&gt; 67890
COMMIT
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the transaction begins with the BEGIN TRANSACTION statement. The two UPDATE statements transfer $500 from the account with the ID 12345 to the account with the ID 67890. Finally, the COMMIT statement ends the transaction and saves the changes made to the database.&lt;/p&gt;

&lt;p&gt;If any part of the transaction fails, such as if there are insufficient funds in the account with the ID 12345, the ROLLBACK statement can be used to undo all the changes made during the transaction and ensure that the database remains in a consistent state.&lt;/p&gt;

&lt;h2&gt;
  
  
  Locking mechanism
&lt;/h2&gt;

&lt;p&gt;In SQL, a locking mechanism is used to control access to data in a database and ensure that multiple transactions can work with the same data without causing conflicts.&lt;/p&gt;

&lt;p&gt;Locking can prevent data inconsistencies and ensure data integrity by preventing multiple transactions from accessing the same data at the same time.&lt;/p&gt;

&lt;p&gt;There are several types of locks available in SQL, including:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Shared lock:
&lt;/h3&gt;

&lt;p&gt;Allows multiple transactions to read the same data at the same time, but prevents any transaction from modifying the data.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Exclusive lock:
&lt;/h3&gt;

&lt;p&gt;Prevents any other transaction from accessing or modifying the data while the lock is held.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Update lock:
&lt;/h3&gt;

&lt;p&gt;Allows multiple transactions to read the same data, but only one transaction can update the data at a time.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Intent lock:
&lt;/h3&gt;

&lt;p&gt;Indicates that a transaction intends to acquire a lock on a particular resource, such as a row or a page.&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Schema lock:
&lt;/h3&gt;

&lt;p&gt;Prevents any other transaction from modifying the schema of a database object while the lock is held.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
Consider a table called "Inventory" with the following columns:&lt;/p&gt;

&lt;p&gt;Item_ID (Primary Key)&lt;br&gt;
Item_Name&lt;br&gt;
Item_Quantity&lt;/p&gt;

&lt;p&gt;To prevent two transactions from updating the same item quantity at the same time, we can use a locking mechanism. &lt;/p&gt;

&lt;p&gt;The following example shows how to use a shared lock to allow multiple transactions to read the same data, but prevent any transaction from modifying the data:&lt;/p&gt;

&lt;p&gt;Transaction 1:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;BEGIN TRANSACTION
SELECT Item_Quantity FROM Inventory WITH &lt;span class="o"&gt;(&lt;/span&gt;UPDLOCK&lt;span class="o"&gt;)&lt;/span&gt; WHERE Item_ID &lt;span class="o"&gt;=&lt;/span&gt; 12345
&lt;span class="nt"&gt;--&lt;/span&gt; Process the data
COMMIT
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Transaction 2:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;BEGIN TRANSACTION
SELECT Item_Quantity FROM Inventory WITH &lt;span class="o"&gt;(&lt;/span&gt;UPDLOCK&lt;span class="o"&gt;)&lt;/span&gt; WHERE Item_ID &lt;span class="o"&gt;=&lt;/span&gt; 12345
&lt;span class="nt"&gt;--&lt;/span&gt; Process the data
COMMIT
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, both transactions acquire an update lock on the row with the Item_ID 12345 using the WITH (UPDLOCK) clause in the SELECT statement. This prevents any other transaction from acquiring an exclusive lock on the same row while the update lock is held, ensuring that only one transaction can modify the data at a time.&lt;/p&gt;

&lt;p&gt;Note that the shared lock acquired by the transactions allows other transactions to read the same data, but not modify it. If a transaction needs to modify the data, it must acquire an exclusive lock on the row, which prevents any other transaction from accessing the data until the lock is released.&lt;/p&gt;

&lt;h2&gt;
  
  
  Database Isolation Levels
&lt;/h2&gt;

&lt;p&gt;In SQL, database isolation levels define how transactions interact with each other and with the data in the database. &lt;/p&gt;

&lt;p&gt;Isolation levels determine the level of concurrency that is allowed in a database system, which can affect the consistency and accuracy of the data.&lt;/p&gt;

&lt;p&gt;There are four commonly used isolation levels in SQL:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Read Uncommitted:
&lt;/h3&gt;

&lt;p&gt;The lowest level of isolation, which allows transactions to read data that has been modified by other transactions, but not yet committed.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Read Committed:
&lt;/h3&gt;

&lt;p&gt;This level of isolation allows transactions to read only committed data, which prevents dirty reads. &lt;/p&gt;

&lt;p&gt;However, it still allows non-repeatable reads, where a transaction reads the same data twice and gets different results because another transaction has modified the data in between.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Repeatable Read:
&lt;/h3&gt;

&lt;p&gt;This level of isolation ensures that a transaction can read the same data multiple times and get the same result, even if another transaction modifies the data in between.&lt;/p&gt;

&lt;p&gt;This level prevents non-repeatable reads, but still allows phantom reads, where a transaction reads a set of rows and another transaction inserts new rows that match the same criteria.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Serializable:
&lt;/h3&gt;

&lt;p&gt;The highest level of isolation, which provides the strongest level of consistency. &lt;/p&gt;

&lt;p&gt;It ensures that transactions are executed as if they were executed sequentially, which prevents dirty reads, non-repeatable reads, and phantom reads. &lt;/p&gt;

&lt;p&gt;However, this level of isolation can lead to a high level of contention, which can affect the performance of the database system.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;Consider a table called "Order_Details" with the following columns:&lt;/p&gt;

&lt;p&gt;Order_ID (Primary Key)&lt;br&gt;
Product_Name&lt;br&gt;
Quantity&lt;/p&gt;

&lt;p&gt;To demonstrate the different isolation levels, we can use the following example:&lt;/p&gt;

&lt;p&gt;Transaction 1:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
BEGIN TRANSACTION
SELECT SUM&lt;span class="o"&gt;(&lt;/span&gt;Quantity&lt;span class="o"&gt;)&lt;/span&gt; FROM Order_Details WHERE Product_Name &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'Product A'&lt;/span&gt;
&lt;span class="nt"&gt;--&lt;/span&gt; Process the data
COMMIT
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Transaction 2:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;SET TRANSACTION ISOLATION LEVEL READ COMMITTED
BEGIN TRANSACTION
SELECT SUM&lt;span class="o"&gt;(&lt;/span&gt;Quantity&lt;span class="o"&gt;)&lt;/span&gt; FROM Order_Details WHERE Product_Name &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'Product A'&lt;/span&gt;
&lt;span class="nt"&gt;--&lt;/span&gt; Process the data
COMMIT

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Transaction 3:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;SET TRANSACTION ISOLATION LEVEL REPEATABLE READ
BEGIN TRANSACTION
SELECT SUM&lt;span class="o"&gt;(&lt;/span&gt;Quantity&lt;span class="o"&gt;)&lt;/span&gt; FROM Order_Details WHERE Product_Name &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'Product A'&lt;/span&gt;
&lt;span class="nt"&gt;--&lt;/span&gt; Process the data
COMMIT
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Transaction 4:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;SET TRANSACTION ISOLATION LEVEL SERIALIZABLE
BEGIN TRANSACTION
SELECT SUM&lt;span class="o"&gt;(&lt;/span&gt;Quantity&lt;span class="o"&gt;)&lt;/span&gt; FROM Order_Details WHERE Product_Name &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'Product A'&lt;/span&gt;
&lt;span class="nt"&gt;--&lt;/span&gt; Process the data
COMMIT
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, each transaction sets a different isolation level and retrieves the sum of the quantity for the product with the name "Product A" from the "Order_Details" table. &lt;/p&gt;

&lt;p&gt;The different isolation levels affect how the transactions interact with each other and with the data in the database, which can lead to different results and different levels of consistency. &lt;/p&gt;

&lt;p&gt;For example, the READ UNCOMMITTED level allows dirty reads, which means that Transaction 1 can read data that has been modified but not yet committed by other transactions. &lt;/p&gt;

&lt;p&gt;On the other hand, the SERIALIZABLE level ensures the highest level of consistency by preventing dirty reads, non-repeatable reads, and phantom reads, but it can also lead to a high level of contention and reduced performance.&lt;/p&gt;

&lt;h2&gt;
  
  
  Triggers
&lt;/h2&gt;

&lt;p&gt;In SQL, a trigger is a special type of stored procedure that is automatically executed in response to certain events or actions in a database. &lt;/p&gt;

&lt;p&gt;Triggers can be used to enforce business rules, maintain data integrity, and automate certain database operations.&lt;/p&gt;

&lt;p&gt;There are two types of triggers in SQL:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. DML Triggers:
&lt;/h3&gt;

&lt;p&gt;These triggers are fired in response to data manipulation language (DML) events, such as INSERT, UPDATE, and DELETE statements.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. DDL Triggers:
&lt;/h3&gt;

&lt;p&gt;These triggers are fired in response to data definition language (DDL) events, such as CREATE, ALTER, and DROP statements.&lt;/p&gt;

&lt;p&gt;Triggers can be defined to execute either before or after the triggering event. A trigger can be defined to execute once for each statement, or once for each row that is affected by the statement.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;Consider a table called "Employee" with the following columns:&lt;/p&gt;

&lt;p&gt;Employee_ID (Primary Key)&lt;br&gt;
Employee_Name&lt;br&gt;
Salary&lt;/p&gt;

&lt;p&gt;To demonstrate the use of triggers, we can create a trigger that automatically updates the "Salary" column of the "Employee" table whenever a new record is inserted into the table. The trigger will double the value of the "Salary" column for each new record.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;CREATE TRIGGER trg_employee_insert
ON Employee
FOR INSERT
AS
BEGIN
UPDATE Employee SET Salary &lt;span class="o"&gt;=&lt;/span&gt; Salary &lt;span class="k"&gt;*&lt;/span&gt; 2 WHERE Employee_ID IN &lt;span class="o"&gt;(&lt;/span&gt;SELECT Employee_ID FROM inserted&lt;span class="o"&gt;)&lt;/span&gt;
END
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the trigger is defined to execute after an insert statement is executed on the "Employee" table. The trigger updates the "Salary" column of the newly inserted record by multiplying it by 2. The "inserted" table is a special table that is available within a trigger and contains the rows that were inserted or modified by the triggering statement.&lt;/p&gt;

&lt;p&gt;Now, if we insert a new record into the "Employee" table with the following statement:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;INSERT INTO Employee &lt;span class="o"&gt;(&lt;/span&gt;Employee_Name, Salary&lt;span class="o"&gt;)&lt;/span&gt; VALUES &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'John'&lt;/span&gt;, 50000&lt;span class="o"&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The trigger will automatically update the "Salary" column of the new record to 100000. Thus, the trigger has enforced a business rule that specifies that all new employees must have a salary that is double the original value.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In conclusion, with a solid understanding of these SQL concepts, users can design and manage databases that are efficient, reliable, and scalable.&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;p&gt;ACID :&lt;br&gt;
&lt;a href="https://www.geeksforgeeks.org/acid-properties-in-dbms/"&gt;https://www.geeksforgeeks.org/acid-properties-in-dbms/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;CAP Theorem : &lt;br&gt;
&lt;a href="https://www.geeksforgeeks.org/the-cap-theorem-in-dbms/"&gt;https://www.geeksforgeeks.org/the-cap-theorem-in-dbms/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Joins : &lt;br&gt;
&lt;a href="https://www.geeksforgeeks.org/sql-join-set-1-inner-left-right-and-full-joins/"&gt;https://www.geeksforgeeks.org/sql-join-set-1-inner-left-right-and-full-joins/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Aggregations, Filters in queries : &lt;a href="https://www.geeksforgeeks.org/aggregate-functions-in-sql/"&gt;https://www.geeksforgeeks.org/aggregate-functions-in-sql/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Normalization : &lt;br&gt;
&lt;a href="https://www.geeksforgeeks.org/normalization-process-in-dbms/"&gt;https://www.geeksforgeeks.org/normalization-process-in-dbms/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Indexes : &lt;br&gt;
&lt;a href="https://www.geeksforgeeks.org/sql-queries-on-clustered-and-non-clustered-indexes/"&gt;https://www.geeksforgeeks.org/sql-queries-on-clustered-and-non-clustered-indexes/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Transactions : &lt;br&gt;
&lt;a href="https://www.geeksforgeeks.org/sql-transactions/"&gt;https://www.geeksforgeeks.org/sql-transactions/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Locking mechanism : &lt;br&gt;
&lt;a href="https://www.geeksforgeeks.org/difference-between-shared-lock-and-exclusive-lock/"&gt;https://www.geeksforgeeks.org/difference-between-shared-lock-and-exclusive-lock/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Database Isolation Levels:&lt;br&gt;
&lt;a href="https://www.geeksforgeeks.org/transaction-isolation-levels-dbms/"&gt;https://www.geeksforgeeks.org/transaction-isolation-levels-dbms/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Triggers : &lt;br&gt;
&lt;a href="https://www.javatpoint.com/triggers-in-sql-server"&gt;https://www.javatpoint.com/triggers-in-sql-server&lt;/a&gt;&lt;/p&gt;

</description>
      <category>sql</category>
      <category>beginners</category>
    </item>
    <item>
      <title>SOLID PRINCIPLES</title>
      <dc:creator>Manisha Kundrapu</dc:creator>
      <pubDate>Mon, 20 Feb 2023 04:44:24 +0000</pubDate>
      <link>https://dev.to/manishakundrapu/solid-principles-1e8o</link>
      <guid>https://dev.to/manishakundrapu/solid-principles-1e8o</guid>
      <description>&lt;p&gt;Object-Oriented Design is essential in software development when it comes to writing code that is flexible, scalable, maintainable, and reusable.&lt;/p&gt;

&lt;p&gt;There are numerous advantages to using OOD, but every developer should understand the SOLID principle in order to create good object-oriented design in programming.&lt;/p&gt;

&lt;p&gt;Robert C. Martin, also known as Uncle Bob, introduced the SOLID principle, which is now a programming coding standard.&lt;/p&gt;

&lt;p&gt;The SOLID principle aids in lowering tight coupling.&lt;/p&gt;

&lt;p&gt;Tight coupling in code should be avoided because it means a collection of classes are heavily dependent on one another.&lt;/p&gt;

&lt;p&gt;Therefore when your classes are loosely coupled, your code is deemed to be of high quality.&lt;/p&gt;

&lt;p&gt;Your code will be less likely to change due to the presence of loosely connected classes, which makes the code to be more reusable, maintainable, versatile, and stable. &lt;/p&gt;

&lt;p&gt;This principle is an abbreviated version of the five principles listed below. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;S - Single-responsiblity Principle&lt;/li&gt;
&lt;li&gt;O - Open-closed Principle&lt;/li&gt;
&lt;li&gt;L - Liskov Substitution Principle&lt;/li&gt;
&lt;li&gt;I - Interface Segregation Principle&lt;/li&gt;
&lt;li&gt;D - Dependency Inversion Principle&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Single-Responsibility Principle (SRP):
&lt;/h2&gt;

&lt;p&gt;According to this principle “a class should have only one reason to change” which means every class should have a single responsibility or single job or single purpose.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;class Birds:
    def __init__&lt;span class="o"&gt;(&lt;/span&gt;self, name: str&lt;span class="o"&gt;)&lt;/span&gt;:
        self.name &lt;span class="o"&gt;=&lt;/span&gt; name

    def get_name&lt;span class="o"&gt;(&lt;/span&gt;self&lt;span class="o"&gt;)&lt;/span&gt; -&amp;gt; str:
        pass

    def save&lt;span class="o"&gt;(&lt;/span&gt;self, Birds: Birds&lt;span class="o"&gt;)&lt;/span&gt;:
        pass
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The aforementioned Birds class transgresses the SRP.&lt;/p&gt;

&lt;p&gt;SRP stipulates that classes should only have one job; nevertheless, in this case, we may identify two , managing the Birds database and managing the Birds properties.&lt;/p&gt;

&lt;p&gt;While the save controls how the Birds are stored in a database, the constructor and get name control how the properties of the Birds are managed.&lt;/p&gt;

&lt;p&gt;If modifications to the program have an impact on how databases are managed, to account for the new modifications, the classes that utilise Birds attributes will need to be modified and recompiled.&lt;/p&gt;

&lt;p&gt;We develop a different class that will be responsible for the sole task of maintaining Birds in a database in order to comply with SRP.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;class Birds:
    def __init__&lt;span class="o"&gt;(&lt;/span&gt;self, name: str&lt;span class="o"&gt;)&lt;/span&gt;:
            self.name &lt;span class="o"&gt;=&lt;/span&gt; name

    def get_name&lt;span class="o"&gt;(&lt;/span&gt;self&lt;span class="o"&gt;)&lt;/span&gt;:
        pass


class BirdsDB:
    def get_Birds&lt;span class="o"&gt;(&lt;/span&gt;self&lt;span class="o"&gt;)&lt;/span&gt; -&amp;gt; Birds:
        pass

    def save&lt;span class="o"&gt;(&lt;/span&gt;self, Birds: Birds&lt;span class="o"&gt;)&lt;/span&gt;:
        pass
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Open-Closed Principle (OCP) :
&lt;/h2&gt;

&lt;p&gt;According to this principle "Objects or entities should be open for extension but closed for modification". &lt;/p&gt;

&lt;p&gt;This means that without modifying the class behaviour , it needs to be extended.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;class Birds:
    def __init__&lt;span class="o"&gt;(&lt;/span&gt;self, name: str&lt;span class="o"&gt;)&lt;/span&gt;:
        self.name &lt;span class="o"&gt;=&lt;/span&gt; name

    def get_name&lt;span class="o"&gt;(&lt;/span&gt;self&lt;span class="o"&gt;)&lt;/span&gt; -&amp;gt; str:
        pass

birds &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;
    Birds&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'parrot'&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;,
    Birds&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'crow'&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="o"&gt;]&lt;/span&gt;

def Birds_Colour&lt;span class="o"&gt;(&lt;/span&gt;birds: list&lt;span class="o"&gt;)&lt;/span&gt;:
    &lt;span class="k"&gt;for &lt;/span&gt;bird &lt;span class="k"&gt;in &lt;/span&gt;birds:
        &lt;span class="k"&gt;if &lt;/span&gt;bird.name &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s1"&gt;'parrot'&lt;/span&gt;:
            print&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'green'&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;

        &lt;span class="k"&gt;elif &lt;/span&gt;bird.name &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s1"&gt;'crow'&lt;/span&gt;:
            print&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'black'&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;

Birds_Colour&lt;span class="o"&gt;(&lt;/span&gt;birds&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The function Birds_Colour does not conform to the open-closed principle because it cannot be closed against new kinds of birds.&lt;/p&gt;

&lt;p&gt;If we add a new bird, crane, We have to modify the Birds_Colour function.&lt;/p&gt;

&lt;p&gt;You see, for every new bird, a new logic is added to the Birds_Colour function. &lt;/p&gt;

&lt;p&gt;This is quite a simple example. When your application grows and becomes complex, you will see that the if statement would be repeated over and over again in the Birds_Colour function each time a new bird is added, all over the application.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;birds &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt;
    Birds&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'parrot'&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;,
    Birds&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'crow'&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;,
    Birds&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'crane'&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="o"&gt;]&lt;/span&gt;

def Birds_Colour&lt;span class="o"&gt;(&lt;/span&gt;birds: list&lt;span class="o"&gt;)&lt;/span&gt;:
    &lt;span class="k"&gt;for &lt;/span&gt;bird &lt;span class="k"&gt;in &lt;/span&gt;birds:
        &lt;span class="k"&gt;if &lt;/span&gt;bird.name &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s1"&gt;'parrot'&lt;/span&gt;:
            print&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'green'&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;elif &lt;/span&gt;bird.name &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s1"&gt;'crow'&lt;/span&gt;:
            print&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'black'&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;elif &lt;/span&gt;bird.name &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s1"&gt;'crane'&lt;/span&gt;:
            print&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'white'&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;

Birds_Colour&lt;span class="o"&gt;(&lt;/span&gt;birds&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;class Birds:
    def __init__&lt;span class="o"&gt;(&lt;/span&gt;self, name: str&lt;span class="o"&gt;)&lt;/span&gt;:
        self.name &lt;span class="o"&gt;=&lt;/span&gt; name

    def get_name&lt;span class="o"&gt;(&lt;/span&gt;self&lt;span class="o"&gt;)&lt;/span&gt; -&amp;gt; str:
        pass

    def Birds_Colour&lt;span class="o"&gt;(&lt;/span&gt;self&lt;span class="o"&gt;)&lt;/span&gt;:
        pass


class parrot&lt;span class="o"&gt;(&lt;/span&gt;Birds&lt;span class="o"&gt;)&lt;/span&gt;:
    def Birds_Colour&lt;span class="o"&gt;(&lt;/span&gt;self&lt;span class="o"&gt;)&lt;/span&gt;:
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s1"&gt;'green'&lt;/span&gt;


class crow&lt;span class="o"&gt;(&lt;/span&gt;Birds&lt;span class="o"&gt;)&lt;/span&gt;:
    def Birds_Colour&lt;span class="o"&gt;(&lt;/span&gt;self&lt;span class="o"&gt;)&lt;/span&gt;:
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s1"&gt;'black'&lt;/span&gt;


class crane&lt;span class="o"&gt;(&lt;/span&gt;Birds&lt;span class="o"&gt;)&lt;/span&gt;:
    def Birds_Colour&lt;span class="o"&gt;(&lt;/span&gt;self&lt;span class="o"&gt;)&lt;/span&gt;:
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s1"&gt;'white'&lt;/span&gt;


def Birds_Colour&lt;span class="o"&gt;(&lt;/span&gt;Birds: list&lt;span class="o"&gt;)&lt;/span&gt;:
    &lt;span class="k"&gt;for &lt;/span&gt;bird &lt;span class="k"&gt;in &lt;/span&gt;birds:
        print&lt;span class="o"&gt;(&lt;/span&gt;bird.Birds_Colour&lt;span class="o"&gt;())&lt;/span&gt;

Birds_Colour&lt;span class="o"&gt;(&lt;/span&gt;Birds&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Birds now has a virtual method Birds_Colour. &lt;/p&gt;

&lt;p&gt;We have each bird extend the Birds class and implement the virtual Birds_Colour method.&lt;/p&gt;

&lt;p&gt;Every bird adds its own implementation on its colour in the Birds_Colour. &lt;/p&gt;

&lt;p&gt;The Birds_Colour iterates through the array of birds and just calls its Birds_Colour method.&lt;/p&gt;

&lt;p&gt;Now, if we add a new bird, Birds_Colour doesn’t need to change. &lt;/p&gt;

&lt;p&gt;All we need to do is add the new bird to the birds array.&lt;br&gt;
Birds_Colour now conforms to the OCP principle.&lt;/p&gt;
&lt;h2&gt;
  
  
  Liskov’s Substitution Principle (LSP):
&lt;/h2&gt;

&lt;p&gt;The principle was introduced by Barbara Liskov in 1987 and according to this principle “Derived or child classes must be substitutable for their base or parent classes“. &lt;/p&gt;

&lt;p&gt;This principle ensures that any class that is the child of a parent class should be usable in place of its parent without any unexpected behavior.&lt;/p&gt;

&lt;p&gt;For example we have a class called Amphibian for animals that can live on both land and water. &lt;/p&gt;

&lt;p&gt;This class has two methods to show the features of an amphibian – swim() and walk().&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;class Amphibian&lt;span class="o"&gt;(&lt;/span&gt;ABC&lt;span class="o"&gt;)&lt;/span&gt;:
    def swim&lt;span class="o"&gt;()&lt;/span&gt; -&amp;gt; bool:
        print&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Can Swim"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; 

    def walk&lt;span class="o"&gt;()&lt;/span&gt; -&amp;gt; bool:
        print&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Can Walk"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; 

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The Amphibian class can extend to a turtle class because turtles are amphibians, so they can inherit the properties of the Amphibian class without altering the logic and purpose of the class.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;class turtle&lt;span class="o"&gt;(&lt;/span&gt;Amphibian&lt;span class="o"&gt;)&lt;/span&gt;:
    def swim&lt;span class="o"&gt;()&lt;/span&gt;:
        &lt;span class="k"&gt;return &lt;/span&gt;print&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"turtles can swim"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; 

    def walk&lt;span class="o"&gt;()&lt;/span&gt;:
        &lt;span class="k"&gt;return &lt;/span&gt;print&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"turtles can walk"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; 

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But we cannot extend the Amphibian class to a shark class because shark only live in water which implies that the walk() method would be irrelevant to the shark class.&lt;/p&gt;

&lt;p&gt;So, when you extend a class, if some of the properties of the initial class are not useful for the new class, the Liskov substitution principle has been violated.&lt;/p&gt;

&lt;p&gt;The solution to this is simple, create interfaces that match the needs of the inheriting class.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;class Swim&lt;span class="o"&gt;(&lt;/span&gt;ABC&lt;span class="o"&gt;)&lt;/span&gt;:
    @abstractmethod
    def swim&lt;span class="o"&gt;(&lt;/span&gt;self&lt;span class="o"&gt;)&lt;/span&gt; -&amp;gt; bool:
        pass

class Walk&lt;span class="o"&gt;(&lt;/span&gt;ABC&lt;span class="o"&gt;)&lt;/span&gt;:
    @abstractmethod
    def walk&lt;span class="o"&gt;(&lt;/span&gt;self&lt;span class="o"&gt;)&lt;/span&gt; -&amp;gt; bool:
        pass

class Amphibian&lt;span class="o"&gt;(&lt;/span&gt;Swim, Walk&lt;span class="o"&gt;)&lt;/span&gt;:
    def swim&lt;span class="o"&gt;(&lt;/span&gt;self&lt;span class="o"&gt;)&lt;/span&gt; -&amp;gt; bool:
        print&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Can Swim"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;return &lt;/span&gt;True

    def walk&lt;span class="o"&gt;(&lt;/span&gt;self&lt;span class="o"&gt;)&lt;/span&gt; -&amp;gt; bool:
        print&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Can Walk"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;return &lt;/span&gt;True

class Turtle&lt;span class="o"&gt;(&lt;/span&gt;Swim, Walk&lt;span class="o"&gt;)&lt;/span&gt;:
    def swim&lt;span class="o"&gt;(&lt;/span&gt;self&lt;span class="o"&gt;)&lt;/span&gt; -&amp;gt; bool:
        print&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Turtles can swim"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;return &lt;/span&gt;True

    def walk&lt;span class="o"&gt;(&lt;/span&gt;self&lt;span class="o"&gt;)&lt;/span&gt; -&amp;gt; bool:
        print&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Turtles can walk"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;return &lt;/span&gt;True
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this updated implementation, we define two interfaces, "Swim" and "Walk", which define the contract that any class implementing them must follow. &lt;/p&gt;

&lt;p&gt;The "Amphibian" class implements both "Swim" and "Walk" interfaces, while the "Turtle" class also implements both interfaces. &lt;/p&gt;

&lt;p&gt;By using interfaces, we ensure that any class implementing the "Swim" and "Walk" interfaces must have the same method signatures as defined in the interface, ensuring adherence to the Liskov Substitution Principle (LSP).&lt;/p&gt;

&lt;h2&gt;
  
  
  Interface Segregation Principle (ISP):
&lt;/h2&gt;

&lt;p&gt;This principle is the first principle that applies to Interfaces instead of classes in SOLID and it is similar to the single responsibility principle. &lt;/p&gt;

&lt;p&gt;It states that “do not force any client to implement an interface which is irrelevant to them“. &lt;/p&gt;

&lt;p&gt;Here your main goal is to focus on avoiding fat interface and give preference to many small client-specific interfaces.&lt;/p&gt;

&lt;p&gt;You should prefer many client interfaces rather than one general interface and each interface should have a specific responsibility.&lt;/p&gt;

&lt;p&gt;In summary, if a class inherits another, it should do so in a manner that all the properties of the inherited class would remain relevant to its functionality.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;class Walker&lt;span class="o"&gt;(&lt;/span&gt;ABC&lt;span class="o"&gt;)&lt;/span&gt;:
  def walk&lt;span class="o"&gt;()&lt;/span&gt; -&amp;gt; bool:
    &lt;span class="k"&gt;return &lt;/span&gt;print&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Can Walk"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; 

class Swimmer&lt;span class="o"&gt;(&lt;/span&gt;ABC&lt;span class="o"&gt;)&lt;/span&gt;:
  def swim&lt;span class="o"&gt;()&lt;/span&gt; -&amp;gt; bool:
    &lt;span class="k"&gt;return &lt;/span&gt;print&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Can Swim"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; 

class turtle&lt;span class="o"&gt;(&lt;/span&gt;Walker, Swimmer&lt;span class="o"&gt;)&lt;/span&gt;:
  def walk&lt;span class="o"&gt;()&lt;/span&gt;:
    &lt;span class="k"&gt;return &lt;/span&gt;print&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"turtles can walk"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; 
  def swim&lt;span class="o"&gt;()&lt;/span&gt;:
    &lt;span class="k"&gt;return &lt;/span&gt;print&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"turtles can swim"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; 

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To run the above code we need to run&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;
class Whale&lt;span class="o"&gt;(&lt;/span&gt;Swimmer&lt;span class="o"&gt;)&lt;/span&gt;:
  def swim&lt;span class="o"&gt;()&lt;/span&gt;:
    &lt;span class="k"&gt;return &lt;/span&gt;print&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Whales can swim"&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; 

&lt;span class="k"&gt;if &lt;/span&gt;__name__ &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"__main__"&lt;/span&gt;:
  turtle.walk&lt;span class="o"&gt;()&lt;/span&gt;
  turtle.swim&lt;span class="o"&gt;()&lt;/span&gt;

  Whale.swim&lt;span class="o"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Dependency Inversion Principle (DIP):
&lt;/h2&gt;

&lt;p&gt;According to this principle "Entities must depend on abstractions, not on concretions. It states that the high-level module must not depend on the low-level module, but they should depend on abstractions".&lt;/p&gt;

&lt;p&gt;Consider the below example, where the DIP has been violated where , switch is a concept that is logically in a layer above the light bulb, and the switch relies on it. &lt;/p&gt;

&lt;p&gt;This will lead to poor extensibility or even circular imports that prevent the program from being interpreted or compiled.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;class LightBulb:

  def __init__&lt;span class="o"&gt;(&lt;/span&gt;self, initial_state: &lt;span class="nv"&gt;bool&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;False&lt;span class="o"&gt;)&lt;/span&gt;:
    self.power &lt;span class="o"&gt;=&lt;/span&gt; initial_state

  def turn_on&lt;span class="o"&gt;(&lt;/span&gt;self&lt;span class="o"&gt;)&lt;/span&gt;:
    self.power &lt;span class="o"&gt;=&lt;/span&gt; True

  def turn_off&lt;span class="o"&gt;(&lt;/span&gt;self&lt;span class="o"&gt;)&lt;/span&gt;:
    self.power &lt;span class="o"&gt;=&lt;/span&gt; False

class Switch:

  def __init__&lt;span class="o"&gt;(&lt;/span&gt;self, light_bulb: LightBulb, pressed: &lt;span class="nv"&gt;bool&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;False&lt;span class="o"&gt;)&lt;/span&gt;:
    self.light_bulb &lt;span class="o"&gt;=&lt;/span&gt; light_bulb
    self.pressed &lt;span class="o"&gt;=&lt;/span&gt; pressed

  def toggle&lt;span class="o"&gt;(&lt;/span&gt;self&lt;span class="o"&gt;)&lt;/span&gt;:
    self.pressed &lt;span class="o"&gt;=&lt;/span&gt; not self.pressed &lt;span class="c"&gt;# Toggle&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;self.pressed:
      self.light_bulb.turn_on&lt;span class="o"&gt;()&lt;/span&gt;
    &lt;span class="k"&gt;else&lt;/span&gt;:
      self.light_bulb.turn_off&lt;span class="o"&gt;()&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Instead of the light bulb telling the switch how the bulb should be handled, the switch should tell the light bulb how to implement it. The naive approach would be to define an interface that tells the light bulb how it should behave to be used with a switch.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;class Device&lt;span class="o"&gt;(&lt;/span&gt;ABC&lt;span class="o"&gt;)&lt;/span&gt;:
  power: boolean

  def __init__&lt;span class="o"&gt;(&lt;/span&gt;self, initial_state: &lt;span class="nv"&gt;bool&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;False&lt;span class="o"&gt;)&lt;/span&gt;:
    self.power &lt;span class="o"&gt;=&lt;/span&gt; initial_state

  def turn_on&lt;span class="o"&gt;(&lt;/span&gt;self&lt;span class="o"&gt;)&lt;/span&gt;:
    raise NotImplementedError

  def turn_off&lt;span class="o"&gt;(&lt;/span&gt;self&lt;span class="o"&gt;)&lt;/span&gt;:
    raise NotImplementedError

class Switch:

  def __init__&lt;span class="o"&gt;(&lt;/span&gt;self, device: Device, pressed: &lt;span class="nv"&gt;bool&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;False&lt;span class="o"&gt;)&lt;/span&gt;:
    self.device &lt;span class="o"&gt;=&lt;/span&gt; device
    self.pressed &lt;span class="o"&gt;=&lt;/span&gt; pressed

  def toggle&lt;span class="o"&gt;(&lt;/span&gt;self&lt;span class="o"&gt;)&lt;/span&gt;:
    self.pressed &lt;span class="o"&gt;=&lt;/span&gt; not self.pressed &lt;span class="c"&gt;# Toggle&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;self.pressed:
      self.device.turn_on&lt;span class="o"&gt;()&lt;/span&gt;
    &lt;span class="k"&gt;else&lt;/span&gt;:
      self.device.turn_off&lt;span class="o"&gt;()&lt;/span&gt;  

class LightBulb&lt;span class="o"&gt;(&lt;/span&gt;Device&lt;span class="o"&gt;)&lt;/span&gt;:

  def turn_on&lt;span class="o"&gt;(&lt;/span&gt;self&lt;span class="o"&gt;)&lt;/span&gt;:
    self.power &lt;span class="o"&gt;=&lt;/span&gt; True

  def turn_off&lt;span class="o"&gt;(&lt;/span&gt;self&lt;span class="o"&gt;)&lt;/span&gt;:
    self.power &lt;span class="o"&gt;=&lt;/span&gt; False

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The dependency has been inverted. Instead of the switch relying on the light bulb, the light bulb now relies on an interface in a higher module. Also, both rely on abstractions, as required by the DIP. &lt;/p&gt;

&lt;p&gt;Last but not least, we also fulfilled the requirement "Abstractions should not depend upon details. Details should depend upon abstractions" - The details of how the device behaves rely on the abstraction (Device interface).&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;SOLID principles are a set of design principles that aim to make software designs more maintainable, scalable, and flexible. By adhering to these principles, developers can create software that is easier to modify, extend, and test, leading to fewer bugs and better performance. Incorporating SOLID principles into the development process helps to reduce the complexity of the codebase and make it easier to understand, resulting in high-quality, maintainable code that meets the needs of users and stakeholders alike.&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;p&gt;The references used are linked below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/watch?v=TMuno5RZNeE"&gt;https://www.youtube.com/watch?v=TMuno5RZNeE&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.youtube.com/playlist?list=PL6n9fhu94yhXjG1w2blMXUzyDrZ_eyOme"&gt;https://www.youtube.com/playlist?list=PL6n9fhu94yhXjG1w2blMXUzyDrZ_eyOme&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.digitalocean.com/community/conceptual_articles/s-o-l-i-d-the-first-five-principles-of-object-oriented-design"&gt;https://www.digitalocean.com/community/conceptual_articles/s-o-l-i-d-the-first-five-principles-of-object-oriented-design&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://medium.com/mindorks/solid-principles-explained-with-examples-79d1ce114ace"&gt;https://medium.com/mindorks/solid-principles-explained-with-examples-79d1ce114ace&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://blog.damavis.com/en/solid-principles-illustrated-in-simple-python-examples/"&gt;https://blog.damavis.com/en/solid-principles-illustrated-in-simple-python-examples/&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Objects and Object Oriented Programming in Python</title>
      <dc:creator>Manisha Kundrapu</dc:creator>
      <pubDate>Thu, 16 Feb 2023 06:40:18 +0000</pubDate>
      <link>https://dev.to/manishakundrapu/objects-and-object-oriented-programming-in-python-4gm6</link>
      <guid>https://dev.to/manishakundrapu/objects-and-object-oriented-programming-in-python-4gm6</guid>
      <description>&lt;p&gt;In Python, as well as in many other programming languages, object-oriented programming (OOP) is a popular programming paradigm. &lt;/p&gt;

&lt;p&gt;OOP is a way of structuring code that allows us to represent real-world objects as software objects.&lt;/p&gt;

&lt;h3&gt;
  
  
  Classes and Objects:
&lt;/h3&gt;

&lt;p&gt;An object is an instance of a class. &lt;/p&gt;

&lt;p&gt;A class is a blueprint for creating objects, which defines the attributes and methods that the objects will have. &lt;/p&gt;

&lt;p&gt;An attribute is a piece of data that an object has, while a method is a function that operates on the object's data.&lt;/p&gt;

&lt;p&gt;Consider the below example,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Person:
    def __init__(self, name, age):
        self.name = name
        self.age = age

    def say_hello(self):
        print(f"Hello, my name is {self.name} and I am {self.age} years old.")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we define a class called Person, which has two attributes, name and age, and one method, say_hello.&lt;/p&gt;

&lt;p&gt;When a new instance of the class is created, a unique method named &lt;strong&gt;init&lt;/strong&gt; is invoked.&lt;/p&gt;

&lt;p&gt;The self parameter refers to the instance of the class that is being created, and it is used to set the values of the name and age attributes.&lt;/p&gt;

&lt;p&gt;Consider the below example,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;person1 = Person("Alice", 25)
In this example, we create a new object called person1 of the Person class, with the name "Alice" and age 25.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can then call the say_hello method on the person1 object:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;person1.say_hello()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will output "Hello, my name is Alice and I am 25 years old."&lt;/p&gt;

&lt;p&gt;OOP allows us to write more modular, reusable, and maintainable code. &lt;/p&gt;

&lt;p&gt;We can define a class once and then create many instances of it, each with their own unique data. We can also create subclasses that inherit attributes and methods from a parent class, and add their own unique attributes and methods.&lt;/p&gt;

&lt;h3&gt;
  
  
  Polymorphism:
&lt;/h3&gt;

&lt;p&gt;An object's capacity to assume different forms is known as polymorphism.&lt;/p&gt;

&lt;p&gt;In Python, polymorphism is achieved through the use of method overriding and method overloading.&lt;/p&gt;

&lt;h4&gt;
  
  
  Method Overriding:
&lt;/h4&gt;

&lt;p&gt;Method overriding is the ability of a subclass to override a method of its superclass. &lt;/p&gt;

&lt;p&gt;Here is an example,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Animal:
    def sound(self):
        print("Animal makes a sound")

class Dog(Animal):
    def sound(self):
        print("Dog barks")

class Cat(Animal):
    def sound(self):
        print("Cat meows")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we define a class called Animal, which has a method called sound.&lt;/p&gt;

&lt;p&gt;We then define two subclasses, Dog and Cat, which override the sound method to provide their own implementation.&lt;/p&gt;

&lt;h4&gt;
  
  
  Method Overloading:
&lt;/h4&gt;

&lt;p&gt;Method overloading is the ability to define multiple methods with the same name, but with different parameters. &lt;/p&gt;

&lt;p&gt;In Python, method overloading is achieved through the use of default arguments. &lt;/p&gt;

&lt;p&gt;Here is an example,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class Math:
    def add(self, a, b, c=0):
        return a + b + c

m = Math()
print(m.add(1, 2)) # Output: 3
print(m.add(1, 2, 3)) # Output: 6
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we define a class called Math, which has a method called add. &lt;/p&gt;

&lt;p&gt;The add method takes two required parameters, a and b, and an optional parameter, c. &lt;/p&gt;

&lt;p&gt;If the c parameter is not provided, it defaults to 0. &lt;/p&gt;

&lt;p&gt;This allows us to call the add method with either two or three arguments.&lt;/p&gt;

&lt;h3&gt;
  
  
  Encapsulation:
&lt;/h3&gt;

&lt;p&gt;Encapsulation is the concept of hiding the internal details of an object from the outside world, and only exposing a public interface. &lt;/p&gt;

&lt;p&gt;This allows us to change the internal implementation of an object without affecting the rest of the program. &lt;/p&gt;

&lt;p&gt;Encapsulation is accomplished in Python by using private properties and functions.&lt;/p&gt;

&lt;p&gt;Private attributes and methods are indicated by a double underscore before their name. &lt;/p&gt;

&lt;p&gt;Here is an example,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class BankAccount:
    def __init__(self, balance):
        self.__balance = balance

    def deposit(self, amount):
        self.__balance += amount

    def withdraw(self, amount):
        if amount &amp;lt;= self.__balance:
            self.__balance -= amount
        else:
            print("Insufficient funds")

    def get_balance(self):
        return self.__balance
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, we define a class called BankAccount, which has a private attribute __balance. &lt;/p&gt;

&lt;p&gt;The deposit and withdraw methods allow us to modify the __balance attribute, while the get_balance method allows us to access the __balance attribute. &lt;/p&gt;

&lt;p&gt;By making the __balance attribute private, we prevent the outside world from directly modifying it.&lt;/p&gt;

&lt;h3&gt;
  
  
  Inheritance:
&lt;/h3&gt;

&lt;p&gt;Inheritance is the concept of creating a new class that is a modified version of an existing class.&lt;/p&gt;

&lt;p&gt;The term "superclass" refers to the current class, and "subclass" to the new class. &lt;/p&gt;

&lt;p&gt;The subclass inherits all of the attributes and methods of the superclass, and can also have its own unique attributes and methods.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class parent_class:
    x = "Parent class variable"

class child_class(parent_class):
    pass

c1 = Test()
obj = child_class()
print(obj.x)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;/p&gt;

&lt;p&gt;Parent class variable&lt;/p&gt;

&lt;p&gt;Here we can observe that we have created the object of class child_class. &lt;/p&gt;

&lt;p&gt;And we do not have any class members in our class child_class. &lt;/p&gt;

&lt;p&gt;But we inherited the properties of class parent_class into class child_class. &lt;/p&gt;

&lt;p&gt;The class variable in class parent_class is inherited from class child_class. &lt;/p&gt;

&lt;p&gt;Hence it is called using the object of class child_class.&lt;/p&gt;

&lt;p&gt;Python supports different types of inheritance, which are:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Single inheritance&lt;/li&gt;
&lt;li&gt;Multiple inheritances&lt;/li&gt;
&lt;li&gt;Multilevel inheritance&lt;/li&gt;
&lt;li&gt;Hierarchical inheritance&lt;/li&gt;
&lt;li&gt;Hybrid inheritance&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  1. Single inheritance:
&lt;/h4&gt;

&lt;p&gt;This is the simplest type of inheritance, where a child class inherits from a single parent class. &lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class ParentClass:
    def parent_method(self):
        print("This is a parent method.")

class ChildClass(ParentClass):
    def child_method(self):
        print("This is a child method.")

child = ChildClass()
child.parent_method()   
child.child_method()  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  2. Multiple inheritances:
&lt;/h4&gt;

&lt;p&gt;This type of inheritance allows a child class to inherit from multiple parent classes. &lt;/p&gt;

&lt;p&gt;In Python, this is achieved by listing the parent classes in a comma-separated list in the parentheses. &lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class ParentClass1:
    def parent1_method(self):
        print("This is a parent 1 method.")

class ParentClass2:
    def parent2_method(self):
        print("This is a parent 2 method.")

class ChildClass(ParentClass1, ParentClass2):
    def child_method(self):
        print("This is a child method.")

child = ChildClass()
child.parent1_method()   
child.parent2_method()  
child.child_method()    
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  3. Multi-level inheritance:
&lt;/h4&gt;

&lt;p&gt;This type of inheritance involves creating a hierarchy of classes, where a child class inherits from a parent class, which in turn, inherits from another parent class. &lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class GrandParentClass:
    def grandparent_method(self):
        print("This is a grandparent method.")

class ParentClass(GrandParentClass):
    def parent_method(self):
        print("This is a parent method.")

class ChildClass(ParentClass):
    def child_method(self):
        print("This is a child method.")

child = ChildClass()
child.grandparent_method()  # This is a grandparent method.
child.parent_method()       # This is a parent method.
child.child_method()        # This is a child method.

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  4. Hierarchical inheritance:
&lt;/h4&gt;

&lt;p&gt;when more than one child class is derived from or inherited from a single (same) parent class. &lt;/p&gt;

&lt;p&gt;Then this type of inheritance is called hierarchical inheritance.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class ParentClass:
    def parent_method(self):
        print("This is a parent method.")

class ChildClass1(ParentClass):
    def child1_method(self):
        print("This is a child 1 method.")

class ChildClass2(ParentClass):
    def child2_method(self):
        print("This is a child 2 method.")

child1 = ChildClass1()
child1.parent_method()   # This is a parent method.
child1.child1_method()   # This is a child1 method.

child2 = ChildClass2()
child2.parent_method()   # This is a parent method.
child2.child2_method()   # This is a child2 method.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  5. Hybrid inheritance:
&lt;/h4&gt;

&lt;p&gt;This type of inheritance combines multiple types of inheritance, such as single, multiple, and multi-level inheritance, to create a more complex inheritance hierarchy.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class GrandParentClass:
    def grandparent_method(self):
        print("This is a grandparent method.")

class ParentClass1(GrandParentClass):
    def parent1_method(self):
        print("This is a parent 1 method.")

class ParentClass2:
    def parent2_method(self):
        print("This is a parent 2 method.")

class ChildClass(ParentClass1, ParentClass2):
    def child_method(self):
        print("This is a child method.")

child = ChildClass()
child.grandparent_method()  
child.parent1_method()     
child.parent2_method()      
child.child_method()        
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the above example, ChildClass is inheriting from two parent classes, ParentClass1 and ParentClass2.&lt;/p&gt;

&lt;p&gt;ParentClass1 itself inherits from GrandParentClass, creating a multi-level inheritance hierarchy.&lt;/p&gt;

&lt;p&gt;Hybrid inheritance can become complex and difficult to understand, so it's important to use it judiciously and keep the hierarchy as simple and intuitive as possible.&lt;/p&gt;

&lt;h3&gt;
  
  
  Data Abstraction:
&lt;/h3&gt;

&lt;p&gt;Data abstraction is a technique used in object-oriented programming to hide the complexity of the data and expose only the necessary information to the user. &lt;/p&gt;

&lt;p&gt;It provides a simplified view of the data, making it easier to understand and work with. &lt;/p&gt;

&lt;p&gt;In Python, data abstraction can be achieved using abstract classes and interfaces.&lt;/p&gt;

&lt;p&gt;Here's an example of data abstraction using abstract classes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from abc import ABC, abstractmethod

class Shape(ABC):
    @abstractmethod
    def area(self):
        pass

    @abstractmethod
    def perimeter(self):
        pass

class Rectangle(Shape):
    def __init__(self, length, width):
        self.length = length
        self.width = width

    def area(self):
        return self.length * self.width

    def perimeter(self):
        return 2 * (self.length + self.width)

class Circle(Shape):
    def __init__(self, radius):
        self.radius = radius

    def area(self):
        return 3.14 * self.radius ** 2

    def perimeter(self):
        return 2 * 3.14 * self.radius

rect = Rectangle(5, 10)
print(rect.area())       # 50
print(rect.perimeter())  # 30

circ = Circle(7)
print(circ.area())       # 153.86
print(circ.perimeter())  # 43.96
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, Shape is an abstract class that defines the interface for calculating the area and perimeter of a shape.&lt;/p&gt;

&lt;p&gt;Rectangle and Circle are concrete classes that implement the Shape interface. &lt;/p&gt;

&lt;p&gt;By using abstract classes, we can create a simplified view of the shapes that hides the complexity of the calculations.&lt;/p&gt;

&lt;p&gt;Another way to achieve data abstraction in Python is using interfaces, which are a collection of abstract methods that define a contract between a class and the outside world. &lt;/p&gt;

&lt;p&gt;The abc module provides the ABC class, which can be used to define interfaces:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from abc import ABC, abstractmethod

class Animal(ABC):
    @abstractmethod
    def make_sound(self):
        pass

class Dog(Animal):
    def make_sound(self):
        return "Woof!"

class Cat(Animal):
    def make_sound(self):
        return "Meow!"

dog = Dog()
print(dog.make_sound())  # Woof!

cat = Cat()
print(cat.make_sound())  # Meow!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, Animal is an interface that defines the make_sound method.&lt;/p&gt;

&lt;p&gt;Dog and Cat are concrete classes that implement the Animal interface by providing their own implementation of the make_sound method. &lt;/p&gt;

&lt;p&gt;By using interfaces, we can create a simplified view of the animals that hides the complexity of their behavior.&lt;/p&gt;

&lt;p&gt;In conclusion, if you want to write more modular, reusable, and maintainable code, object-oriented programming (OOP) in Python is a great choice. With OOP, you can represent real-world objects as software objects and write code that is easier to maintain, debug, and extend. By defining classes that encapsulate attributes and methods, you can create many instances of objects with unique data, and even create subclasses that inherit attributes and methods from a parent class. With these powerful concepts, you can build complex systems and solve real-world problems with ease. Whether you are a beginner or an experienced developer, mastering OOP in Python is a skill that will undoubtedly take your programming abilities to the next level.&lt;/p&gt;

&lt;h3&gt;
  
  
  References:
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;GeeksforGeeks - "Python OOPs Concepts." &lt;a href="https://www.geeksforgeeks.org/python-oops-concepts/" rel="noopener noreferrer"&gt;https://www.geeksforgeeks.org/python-oops-concepts/&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>discuss</category>
    </item>
    <item>
      <title>Python String Methods</title>
      <dc:creator>Manisha Kundrapu</dc:creator>
      <pubDate>Thu, 16 Feb 2023 04:17:03 +0000</pubDate>
      <link>https://dev.to/manishakundrapu/python-string-methods-epi</link>
      <guid>https://dev.to/manishakundrapu/python-string-methods-epi</guid>
      <description>&lt;p&gt;Python provides a wide range of methods that can be applied on string objects. &lt;/p&gt;

&lt;p&gt;Here are most of the string methods available in Python:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. capitalize():
&lt;/h3&gt;

&lt;p&gt;The capitalize() method converts the first character of a string to an uppercase letter and all other alphabets to lowercase.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax&lt;/strong&gt; : string.capitalize()&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;string = "hello world"
capitalized_string = string.capitalize()
print(capitalized_string)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;Hello world&lt;/p&gt;

&lt;h3&gt;
  
  
  2. casefold():
&lt;/h3&gt;

&lt;p&gt;The casefold() method converts all characters of the string into lowercase letters and returns a new string.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax&lt;/strong&gt; : str.casefold()&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;string = "HELLO WORLD"
casefolded_string = string.casefold()
print(casefolded_string)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;hello world&lt;/p&gt;

&lt;h3&gt;
  
  
  3. center():
&lt;/h3&gt;

&lt;p&gt;The center() method returns a new centered string after padding it with the specified character.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax&lt;/strong&gt; : str.center(width, [fillchar])&lt;/p&gt;

&lt;p&gt;width - length of the string with padded characters&lt;br&gt;
fillchar (optional) - padding character&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;string = "hello"
centered_string = string.center(10, "-")
print(centered_string)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;--hello---&lt;/p&gt;

&lt;h3&gt;
  
  
  4. count():
&lt;/h3&gt;

&lt;p&gt;This method returns the number of non-overlapping occurrences of a substring in the string. You can also specify the start and end positions to search within the string.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax&lt;/strong&gt; : string.count(substring, start=..., end=...)&lt;/p&gt;

&lt;p&gt;substring - string whose count is to be found.&lt;br&gt;
start (Optional) - starting index within the string where search starts.&lt;br&gt;
end (Optional) - ending index within the string where search ends.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;string = "hello world"
count = string.count("o")
print(count)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;2&lt;/p&gt;

&lt;h3&gt;
  
  
  5. encode():
&lt;/h3&gt;

&lt;p&gt;This method returns an encoded version of the string using the specified encoding.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax&lt;/strong&gt; : encode(encoding="utf-8", errors="strict")&lt;/p&gt;

&lt;p&gt;By default, the encode() method doesn't require any parameters.&lt;/p&gt;

&lt;p&gt;It returns an utf-8 encoded version of the string. In case of failure, it raises a UnicodeDecodeError exception.&lt;/p&gt;

&lt;p&gt;However, it takes two parameters:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;encoding : the encoding type a string has to be encoded to.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;errors : response when encoding fails. &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There are six types of error response.&lt;/p&gt;

&lt;p&gt;strict - default response which raises a UnicodeDecodeError exception on failure.&lt;/p&gt;

&lt;p&gt;ignore - ignores the unencodable unicode from the result.&lt;/p&gt;

&lt;p&gt;replace - replaces the unencodable unicode to a question mark.&lt;/p&gt;

&lt;p&gt;xmlcharrefreplace - inserts XML character reference instead of unencodable unicode.&lt;/p&gt;

&lt;p&gt;backslashreplace - inserts a \uNNNN escape sequence instead of unencodable unicode.&lt;/p&gt;

&lt;p&gt;namereplace - inserts a \N{...} escape sequence instead of unencodable unicode.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;string = "hello world"
encoded_string = string.encode("utf-8")
print(encoded_string)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;b'hello world'&lt;/p&gt;

&lt;h3&gt;
  
  
  6. endswith():
&lt;/h3&gt;

&lt;p&gt;This method returns True if the string ends with the specified suffix. You can also specify the start and end positions to search within the string.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax&lt;/strong&gt; : endswith(suffix[, start[, end]])&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;string = "hello world"
ends_with = string.endswith("ld")
print(ends_with)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;True&lt;/p&gt;

&lt;h3&gt;
  
  
  7. expandtabs():
&lt;/h3&gt;

&lt;p&gt;The expandtabs() method returns a copy of string with all tab characters '\t' replaced with whitespace characters until the next multiple of tabsize parameter.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax&lt;/strong&gt; : string.expandtabs(tabsize)&lt;/p&gt;

&lt;p&gt;The expandtabs() takes an integer tabsize argument. The default tabsize is 8.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;string = "hello\tworld"
expanded_string = string.expandtabs(4)
print(expanded_string)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;hello   world&lt;/p&gt;

&lt;h3&gt;
  
  
  8. find():
&lt;/h3&gt;

&lt;p&gt;This method returns the lowest index of the first occurrence of a substring in the string. &lt;br&gt;
If the substring is not found, it returns -1. &lt;br&gt;
You can also specify the start and end positions to search within the string.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax&lt;/strong&gt; : find(sub[, start[, end]])&lt;/p&gt;

&lt;p&gt;sub - It is the substring to be searched in the str string.&lt;/p&gt;

&lt;p&gt;start and end (optional) - The range str[start:end] within which substring is searched.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;string = "hello world"
index = string.find("o")
print(index)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;4&lt;/p&gt;

&lt;h3&gt;
  
  
  9. format() :
&lt;/h3&gt;

&lt;p&gt;This method formats the string using the specified arguments.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax&lt;/strong&gt; : format(*args, **kwargs)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;name = "Alice"
age = 30
formatted_string = "My name is {0} and I am {1} years old".format(name, age)
print(formatted_string)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;My name is Alice and I am 30 years old&lt;/p&gt;

&lt;h3&gt;
  
  
  10. format_map():
&lt;/h3&gt;

&lt;p&gt;This method formats the string using the specified mapping.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax&lt;/strong&gt; : str.format_map(mapping)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mapping = {"name": "Alice", "age": 30}
formatted_string = "My name is {name} and I am {age} years old".format_map(mapping)
print(formatted_string)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;My name is Alice and I am 30 years old&lt;/p&gt;

&lt;h3&gt;
  
  
  11. index():
&lt;/h3&gt;

&lt;p&gt;The index() method returns the index of the first occurrence of a substring in a string. If the substring is not found, it raises a ValueError.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax&lt;/strong&gt; : string.index(substring[, start[, end]])&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;string = "Hello World"
print(string.index("o")) # Output: 4
print(string.index("ld")) # Output: 9
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  12. isalnum():
&lt;/h3&gt;

&lt;p&gt;The isalnum() method returns True if all the characters in the string are alphanumeric (letters or numbers), and there is at least one character. Otherwise, it returns False.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax&lt;/strong&gt; : string.isalnum()&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;string = "Hello123"
print(string.isalnum()) # Output: True
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;string = "Hello123@"
print(string.isalnum()) # Output: False
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  13. isalpha():
&lt;/h3&gt;

&lt;p&gt;The isalpha() method returns True if all the characters in the string are alphabets (letters), and there is at least one character. Otherwise, it returns False.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax&lt;/strong&gt; : string.isalpha()&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;string = "Hello"
print(string.isalpha()) # Output: True
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;string = "Hello123"
print(string.isalpha()) # Output: False
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  14. isdecimal():
&lt;/h3&gt;

&lt;p&gt;The isdecimal() method returns True if all the characters in the string are decimal (numbers), and there is at least one character. Otherwise, it returns False.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax&lt;/strong&gt; : string.isdecimal()&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;string = "12345"
print(string.isdecimal()) # Output: True
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;string = "12345abc"
print(string.isdecimal()) # Output: False
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  15. isdigit():
&lt;/h3&gt;

&lt;p&gt;The isdigit() method returns True if all the characters in the string are digits (0-9), and there is at least one character. Otherwise, it returns False.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax&lt;/strong&gt; : string.isdigit()&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;string = "12345"
print(string.isdigit()) # Output: True
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;string = "12345abc"
print(string.isdigit()) # Output: False
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  16. isidentifier():
&lt;/h3&gt;

&lt;p&gt;The isidentifier() method returns True if the string is a valid Python identifier. A valid identifier is a sequence of letters, digits, or underscore characters that starts with a letter or an underscore.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax&lt;/strong&gt; : string.isidentifier()&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;string = "my_variable"
print(string.isidentifier()) # Output: True
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;string = "123variable"
print(string.isidentifier()) # Output: False
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  17. islower():
&lt;/h3&gt;

&lt;p&gt;The islower() method returns True if all the alphabetic characters in the string are lowercase. Otherwise, it returns False.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax&lt;/strong&gt; : string.islower()&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;string = "hello world"
print(string.islower()) # Output: True
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;string = "Hello World"
print(string.islower()) # Output: False
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  18. isnumeric():
&lt;/h3&gt;

&lt;p&gt;The isnumeric() method returns True if all the characters in the string are numeric characters. Otherwise, it returns False.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax&lt;/strong&gt; : string.isnumeric()&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;string = "123"
print(string.isnumeric()) # Output: True
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;string = "123abc"
print(string.isnumeric()) # Output: False
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  19. isprintable():
&lt;/h3&gt;

&lt;p&gt;The isprintable() method returns True if all the characters in the string are printable or the string is empty. Otherwise, it returns False. A character is considered printable if it is not a control character.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax&lt;/strong&gt; : string.isprintable()&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;string = "Hello World!"
print(string.isprintable()) # Output: True
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;string = "\nHello World!"
print(string.isprintable()) # Output: False
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  20. isspace():
&lt;/h3&gt;

&lt;p&gt;The isspace() method returns True if all the characters in the string are whitespace characters. Otherwise, it returns False. A whitespace character is a space, tab, newline, or any other character that is considered a space.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax&lt;/strong&gt; : string.isspace()&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;string = "   \t\n"
print(string.isspace()) # Output: True
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;string = " Hello World "
print(string.isspace()) # Output: False
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  21. istitle():
&lt;/h3&gt;

&lt;p&gt;The istitle() method returns True if the string is a titlecased string, i.e., the first character of each word in the string is in uppercase and all other characters are in lowercase. Otherwise, it returns False.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax&lt;/strong&gt; : string.istitle()&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;string = "Hello World"
print(string.istitle()) # Output: False
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;string = "Hello, World!"
print(string.istitle()) # Output: True
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  22. isupper():
&lt;/h3&gt;

&lt;p&gt;The isupper() method returns True if all the alphabetic characters in the string are uppercase. Otherwise, it returns False.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax&lt;/strong&gt;: string.isupper()&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;string = "HELLO WORLD"
print(string.isupper()) # Output: True
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;string = "Hello World"
print(string.isupper()) # Output: False
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  23. join():
&lt;/h3&gt;

&lt;p&gt;The join() method concatenates a list of strings using the specified string as the separator. It returns a new string that is the concatenation of all the strings in the list, separated by the specified string.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax&lt;/strong&gt; : separator.join(iterable)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;words = ["Hello", "World"]
separator = ", "
print(separator.join(words)) # Output: "Hello, World"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;words = ["1", "2", "3"]
separator = "-"
print(separator.join(words)) # Output: "1-2-3"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  24. ljust():
&lt;/h3&gt;

&lt;p&gt;The ljust() method returns a left-justified version of the string. It pads the original string with a specified character (by default, a space character) on the right side until the resulting string reaches the specified length.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax&lt;/strong&gt; : string.ljust(width[, fillchar])&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;string = "Hello"
print(string.ljust(10)) # Output: "Hello     "
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;string = "Hello"
print(string.ljust(10, "-")) # Output: "Hello-----"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  25. lower():
&lt;/h3&gt;

&lt;p&gt;The lower() method returns a new string with all the alphabetic characters in the original string converted to lowercase.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax&lt;/strong&gt; : string.lower()&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;string = "Hello World"
print(string.lower()) # Output: "hello world"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;string = "123"
print(string.lower()) # Output: "123"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  26. lstrip():
&lt;/h3&gt;

&lt;p&gt;The lstrip() method returns a new string with all leading whitespace characters removed. By default, it removes all whitespace characters, but you can also specify a specific set of characters to remove.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax&lt;/strong&gt; : string.lstrip([chars])&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;string = "  Hello World  "
print(string.lstrip()) # Output: "Hello World  "
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;string = "====Hello World==="
print(string.lstrip("=")) # Output: "Hello World==="
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  27. maketrans():
&lt;/h3&gt;

&lt;p&gt;The maketrans() method creates a translation table that can be used with the translate() method to replace characters in a string.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax&lt;/strong&gt; : str.maketrans(x[, y[, z]])&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;intab = "aeiou"
outtab = "12345"
translation_table = str.maketrans(intab, outtab)
string = "Hello World"
print(string.translate(translation_table)) 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;: &lt;/p&gt;

&lt;p&gt;"H2ll4 W4rld"&lt;/p&gt;

&lt;h3&gt;
  
  
  28. partition():
&lt;/h3&gt;

&lt;p&gt;The partition() method separates a string into three parts based on the first occurrence of a specified separator. It returns a tuple containing the left part of the string, the separator itself, and the right part of the string.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax&lt;/strong&gt; : string.partition(separator)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;string = "Hello, World!"
print(string.partition(",")) 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;: &lt;/p&gt;

&lt;p&gt;("Hello", ",", " World!")&lt;/p&gt;

&lt;h3&gt;
  
  
  29. replace():
&lt;/h3&gt;

&lt;p&gt;The replace() method returns a new string with all occurrences of a specified substring replaced with another substring.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax&lt;/strong&gt; : string.replace(old, new[, count])&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;string = "Hello, World!"
print(string.replace(",", "-")) 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;: "Hello- World!"&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;string = "Hello, World!"
print(string.replace(",", "-", 1)) 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;: "Hello- World!"&lt;/p&gt;

&lt;h3&gt;
  
  
  30. rfind():
&lt;/h3&gt;

&lt;p&gt;The rfind() method searches a string for a specified substring starting from the end of the string and returns the index of the last occurrence of the substring. If the substring is not found, it returns -1.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax&lt;/strong&gt; : string.rfind(sub[, start[, end]])&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt; :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;string = "Hello, World!"
print(string.rfind("l")) # Output: 10
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;string = "Hello, World!"
print(string.rfind("x")) # Output: -1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  31. rindex():
&lt;/h3&gt;

&lt;p&gt;The rindex() method is similar to the index() method, but it searches for a substring starting from the end of the string instead of the beginning. It raises a ValueError if the substring is not found.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax&lt;/strong&gt; : string.rindex(sub[, start[, end]])&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;string = "Hello, World!"
print(string.rindex("o")) # Output: 8
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;string = "Hello, World!"
print(string.rindex("x")) 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;: &lt;/p&gt;

&lt;p&gt;ValueError: substring not found&lt;/p&gt;

&lt;h3&gt;
  
  
  32. rjust():
&lt;/h3&gt;

&lt;p&gt;The rjust() method returns a right-justified version of the string. It pads the original string with a specified character (by default, a space character) on the left side until the resulting string reaches the specified length.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax&lt;/strong&gt; : string.rjust(width[, fillchar])&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;string = "Hello"
print(string.rjust(10)) # Output: "     Hello"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;string = "Hello"
print(string.rjust(10, "-")) # Output: "-----Hello"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  33. rpartition():
&lt;/h3&gt;

&lt;p&gt;The rpartition() method is similar to the partition() method, but it searches for a separator starting from the end of the string instead of the beginning.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax&lt;/strong&gt; : string.rpartition(separator)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;string = "Hello, World!"
print(string.rpartition(",")) 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;: &lt;/p&gt;

&lt;p&gt;("Hello, World", ",", "")&lt;/p&gt;

&lt;h3&gt;
  
  
  34. rsplit():
&lt;/h3&gt;

&lt;p&gt;The rsplit() method is similar to the split() method, but it splits the string from the right end instead of the left. You can also specify the maximum number of splits to perform.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax&lt;/strong&gt;: string.rsplit([sep[, maxsplit]])&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;string = "Hello World, How are you?"
print(string.rsplit(",", 1)) 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;: &lt;/p&gt;

&lt;p&gt;["Hello World", " How are you?"]&lt;/p&gt;

&lt;h3&gt;
  
  
  35. rstrip():
&lt;/h3&gt;

&lt;p&gt;The rstrip() method returns a new string with all trailing whitespace characters removed. By default, it removes all whitespace characters, but you can also specify a specific set of characters to remove.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax&lt;/strong&gt; : string.rstrip([chars])&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;string = "  Hello World  "
print(string.rstrip()) # Output: "  Hello World"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;string = "====Hello World==="
print(string.rstrip("=")) # Output: "====Hello World"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  36. split():
&lt;/h3&gt;

&lt;p&gt;The split() method splits a string into a list of substrings based on a specified separator. By default, it splits the string on whitespace characters, but you can also specify a different separator.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax&lt;/strong&gt; : string.split([sep[, maxsplit]])&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;string = "Hello World, How are you?"
print(string.split()) 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;: ["Hello", "World,", "How", "are", "you?"]&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;string = "Hello-World-How-are-you?"
print(string.split("-")) 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;: ["Hello", "World", "How", "are", "you?"]&lt;/p&gt;

&lt;h3&gt;
  
  
  37. splitlines():
&lt;/h3&gt;

&lt;p&gt;The splitlines() method splits a string into a list of substrings based on newline characters. It works on both Windows and Unix-style newline characters.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax&lt;/strong&gt; : string.splitlines([keepends])&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;string = "Hello\nWorld\nHow\nare\nyou?"
print(string.splitlines()) 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;: &lt;/p&gt;

&lt;p&gt;["Hello", "World", "How", "are", "you?"]&lt;/p&gt;

&lt;h3&gt;
  
  
  38. startswith():
&lt;/h3&gt;

&lt;p&gt;The startswith() method returns True if a string starts with a specified substring; otherwise, it returns False.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax&lt;/strong&gt; : string.startswith(substring[, start[, end]])&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;string = "Hello, World!"
print(string.startswith("Hello")) # Output: True
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;string = "Hello, World!"
print(string.startswith("World", 7)) # Output: True
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  39. strip():
&lt;/h3&gt;

&lt;p&gt;The strip() method returns a new string with all leading and trailing whitespace characters removed. By default, it removes all whitespace characters, but you can also specify a specific set of characters to remove.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax&lt;/strong&gt; : string.strip([chars])&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;string = "  Hello World  "
print(string.strip()) # Output: "Hello World"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;string = "====Hello World==="
print(string.strip("=")) # Output: "Hello World"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  40. swapcase():
&lt;/h3&gt;

&lt;p&gt;The swapcase() method returns a new string with all uppercase characters converted to lowercase and all lowercase characters converted to uppercase.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax&lt;/strong&gt; : string.swapcase()&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;string = "Hello, World!"
print(string.swapcase())
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;: &lt;/p&gt;

&lt;p&gt;"hELLO, wORLD!"&lt;/p&gt;

&lt;h3&gt;
  
  
  41. title():
&lt;/h3&gt;

&lt;p&gt;The title() method returns a new string with the first character of each word in the string capitalized and the remaining characters in lowercase.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax&lt;/strong&gt; : string.title()&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;string = "hello world"
print(string.title()) 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;: &lt;/p&gt;

&lt;p&gt;"Hello World"&lt;/p&gt;

&lt;h3&gt;
  
  
  42. translate():
&lt;/h3&gt;

&lt;p&gt;The translate() method returns a new string where some specified characters are replaced with the character described in a dictionary, or in a mapping table.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax&lt;/strong&gt; : string.translate(table)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;string = "Hello, World!"
translation_table = str.maketrans("o", "e")
print(string.translate(translation_table)) 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;: &lt;/p&gt;

&lt;p&gt;"Helle, Werld!"&lt;/p&gt;

&lt;h3&gt;
  
  
  43. upper():
&lt;/h3&gt;

&lt;p&gt;The upper() method returns a new string with all the characters in uppercase.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax&lt;/strong&gt; : string.upper()&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;string = "Hello, World!"
print(string.upper()) 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;: &lt;/p&gt;

&lt;p&gt;"HELLO, WORLD!"&lt;/p&gt;

&lt;h3&gt;
  
  
  44. zfill():
&lt;/h3&gt;

&lt;p&gt;The zfill() method pads a numeric string with zeros on the left side to fill a specified width. It does not modify the original string.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax&lt;/strong&gt; : string.zfill(width)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;string = "42"
print(string.zfill(5)) # Output: "00042"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;string = "-42"
print(string.zfill(5)) # Output: "-0042"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>python</category>
    </item>
    <item>
      <title>Python Array Methods</title>
      <dc:creator>Manisha Kundrapu</dc:creator>
      <pubDate>Thu, 16 Feb 2023 01:30:22 +0000</pubDate>
      <link>https://dev.to/manishakundrapu/python-array-methods-loe</link>
      <guid>https://dev.to/manishakundrapu/python-array-methods-loe</guid>
      <description>&lt;p&gt;In Python, an array is a container that holds a fixed number of items of the same type.&lt;/p&gt;

&lt;p&gt;Arrays are useful for working with large amounts of data that need to be accessed quickly. &lt;/p&gt;

&lt;p&gt;Python provides a built-in module called "array" for working with arrays.&lt;/p&gt;

&lt;p&gt;Here are some commonly used methods for working with arrays in Python:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Creating an array:
&lt;/h3&gt;

&lt;p&gt;To create an array in Python, you first need to import the "array" module. &lt;/p&gt;

&lt;p&gt;Then, you can create an array using the "array" function and passing it a type code and a sequence of values.&lt;/p&gt;

&lt;p&gt;‘b’ – signed char&lt;/p&gt;

&lt;p&gt;‘B’ – unsigned char&lt;/p&gt;

&lt;p&gt;‘d’ – double&lt;/p&gt;

&lt;p&gt;‘f’ – float&lt;/p&gt;

&lt;p&gt;‘i’ – signed int&lt;/p&gt;

&lt;p&gt;‘I’ – unsigned int&lt;/p&gt;

&lt;p&gt;‘h’ – signed short&lt;/p&gt;

&lt;p&gt;‘H’ – unsigned short&lt;/p&gt;

&lt;p&gt;‘l’ – signed long&lt;/p&gt;

&lt;p&gt;‘L’ – unsigned long&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import array
ar = array.array('i', [11,12,13,14])
print(ar)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;array('i', [11,12,13,14])&lt;/p&gt;

&lt;h3&gt;
  
  
  2. append():
&lt;/h3&gt;

&lt;p&gt;This method adds the specified value to the end of the array.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax&lt;/strong&gt; : array_name.append(item)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import array
arr = array.array('i', [1, 2, 3])
arr.append(4)
print(arr)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;array('i', [1, 2, 3, 4])&lt;/p&gt;

&lt;h3&gt;
  
  
  3. remove():
&lt;/h3&gt;

&lt;p&gt;This method eliminates the first instance of the supplied value from the array.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax&lt;/strong&gt; : array_name.remove(item)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import array
arr = array.array('i', [1, 2, 3, 2])
arr.remove(2)
print(arr)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;array('i', [1, 3, 2])&lt;/p&gt;

&lt;h3&gt;
  
  
  4. sort():
&lt;/h3&gt;

&lt;p&gt;The array's elements are sorted using this method.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax&lt;/strong&gt; : array_name.sort()&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import array
arr = array.array('i', [5, 2, 1, 4, 3])
arr.sort()
print(arr)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;array('i', [1, 2, 3, 4, 5])&lt;/p&gt;

&lt;h3&gt;
  
  
  5. extend():
&lt;/h3&gt;

&lt;p&gt;This method adds the elements from the specified iterable to the end of the array.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax&lt;/strong&gt; : extend(iterable)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import array
arr1 = array.array('i', [1, 2, 3])
arr2 = array.array('i', [4, 5, 6])
arr1.extend(arr2)
print(arr1)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;array('i', [1, 2, 3, 4, 5, 6]) &lt;/p&gt;

&lt;h3&gt;
  
  
  6. insert():
&lt;/h3&gt;

&lt;p&gt;This method inserts the specified value at the specified index.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax&lt;/strong&gt; : insert(index, value)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import array
arr = array.array('i', [1, 2, 3])
arr.insert(1, 4)
print(arr)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;array('i', [1, 4, 2, 3])&lt;/p&gt;

&lt;h3&gt;
  
  
  7. pop():
&lt;/h3&gt;

&lt;p&gt;The element at the supplied index is removed and returned by this method. If no index is specified, it removes and returns the last element.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax&lt;/strong&gt; : pop(index=-1)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import array
arr = array.array('i', [1, 2, 3])
removed_element = arr.pop(1)
print(arr)
print(removed_element)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;array('i', [1, 3])&lt;br&gt;
2&lt;/p&gt;
&lt;h3&gt;
  
  
  8. index():
&lt;/h3&gt;

&lt;p&gt;The index() method returns the index of the first occurrence of a specified element in the array.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax&lt;/strong&gt; : array.index(element[, start[, end]])&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import array
a = array.array('i', [1, 2, 3, 2])
print(a.index(2)) 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;: 1&lt;/p&gt;

&lt;h3&gt;
  
  
  9. reverse():
&lt;/h3&gt;

&lt;p&gt;The order of the array's elements is reversed by this method.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax&lt;/strong&gt; : reverse()&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import array
arr = array.array('i', [1, 2, 3])
arr.reverse()
print(arr)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;array('i', [3, 2, 1]) &lt;/p&gt;

&lt;h3&gt;
  
  
  10. count():
&lt;/h3&gt;

&lt;p&gt;This method returns the number of times the specified value appears in the array.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax&lt;/strong&gt; : count(value)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import array
arr = array.array('i', [1, 2, 3, 2])
count = arr.count(2)
print(count)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;: 2&lt;/p&gt;

&lt;h3&gt;
  
  
  11. typecode:
&lt;/h3&gt;

&lt;p&gt;The typecode attribute of an array returns the type code character used to create the array.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax&lt;/strong&gt; : array.typecode&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import array
a = array.array('i', [1, 2, 3, 4])
print(a.typecode)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;: "i"&lt;/p&gt;

&lt;h3&gt;
  
  
  12. itemsize:
&lt;/h3&gt;

&lt;p&gt;The itemsize attribute of an array returns the size of each element in bytes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax&lt;/strong&gt; : array.itemsize&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import array
a = array.array('i', [1, 2, 3, 4])
print(a.itemsize)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;: 4&lt;/p&gt;

&lt;h3&gt;
  
  
  13. buffer_info():
&lt;/h3&gt;

&lt;p&gt;The buffer_info() method returns a tuple representing the address of the array's buffer and the size of the buffer in bytes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax&lt;/strong&gt; : array.buffer_info()&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import array
a = array.array('i', [1, 2, 3, 4])
print(a.buffer_info()) 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;: (139953048219200, 16)&lt;/p&gt;

&lt;h3&gt;
  
  
  14. fromlist():
&lt;/h3&gt;

&lt;p&gt;The fromlist() method appends a list to the end of an array.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax&lt;/strong&gt; : array.fromlist(list)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import array
ar = array.array('i', [1, 2, 3, 4])
ar.fromlist([15, 16, 17, 18])
print(ar) 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;: &lt;/p&gt;

&lt;p&gt;array('i', [1, 2, 3, 4, 15, 16, 17, 18])&lt;/p&gt;

&lt;h3&gt;
  
  
  15. tolist():
&lt;/h3&gt;

&lt;p&gt;The tolist() method returns a list containing all the elements of an array.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax&lt;/strong&gt; : array.tolist()&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import array
a = array.array('i', [1, 2, 3, 4])
print(a.tolist()) 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;: &lt;/p&gt;

&lt;p&gt;[1, 2, 3, 4]&lt;/p&gt;

&lt;h3&gt;
  
  
  16. copy():
&lt;/h3&gt;

&lt;p&gt;A shallow copy of the array is what is returned by the copy() method.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax&lt;/strong&gt; : array.copy()&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import array
a = array.array('i', [11, 12, 13, 14])
cpy_a = a.copy()
print(cpy_a) 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;: &lt;/p&gt;

&lt;p&gt;array('i', [11, 12, 13, 14])&lt;/p&gt;

&lt;h3&gt;
  
  
  17. clear():
&lt;/h3&gt;

&lt;p&gt;The clear() method removes all the elements from the array.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Syntax&lt;/strong&gt; : array.clear()&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import array
a = array.array('i', [1, 2, 3, 4])
a.clear()
print(a) 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;array('i', [])&lt;/p&gt;

</description>
      <category>react</category>
    </item>
    <item>
      <title>Awk</title>
      <dc:creator>Manisha Kundrapu</dc:creator>
      <pubDate>Thu, 02 Feb 2023 06:04:18 +0000</pubDate>
      <link>https://dev.to/manishakundrapu/awk-i4b</link>
      <guid>https://dev.to/manishakundrapu/awk-i4b</guid>
      <description>&lt;p&gt;Awk is utilised for data manipulation and report generation. The awk command does not require compilation and enables the usage of variables, string functions, numeric functions, and logical operators .&lt;/p&gt;

&lt;p&gt;Awk allows programmers to create brief but powerful programmes in the form of statements that specify text patterns to be looked for in each line of a document and the action that should be taken when a match is found . Awk is primarily utilised for processing and scanning patterns . In order to determine whether any files include lines that fit the required patterns, it examines one or more of them . If so, it takes the appropriate steps .&lt;/p&gt;

&lt;p&gt;The developers' names Aho, Weinberger, and Kernighan are shortened to Awk .&lt;/p&gt;

&lt;p&gt;AWK operations include the following : &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Line-by-line file scanning &lt;/li&gt;
&lt;li&gt;Field splitting &lt;/li&gt;
&lt;li&gt;Input line/field comparison with pattern &lt;/li&gt;
&lt;li&gt;Executes an action on matched lines&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Its often used for Producing prepared reports and transforming data files .&lt;/p&gt;

&lt;p&gt;Programming constructs include output line formatting , string and arithmetic operations , conditionals and loops .&lt;/p&gt;

&lt;h2&gt;
  
  
  Built-In Variables In Awk
&lt;/h2&gt;

&lt;p&gt;The field variables that divide a line of text into discrete words or parts known as fields are included in Awk as built-in variables and are denoted by the numbers $1, $2, $3, and so on ($0 is the complete line) .&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;NR: The NR command keeps track of the number of input records at all times .&lt;/li&gt;
&lt;li&gt;NF: The NF command keeps track of how many fields are present in the current input record .&lt;/li&gt;
&lt;li&gt;FS: Field separator characters are used to separate fields on the input line and are contained in the FS command . Space and tab characters or white space are used as the default . To modify the field separator, FS can be moved to another character (usually in BEGIN) .&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Syntax :
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;awk options 'criteria {action}' input_file &amp;gt; output_file
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;-f program-file : Instead of reading from the first command line parameter, this is used to read the AWK programme source from .
the file program-file.&lt;/li&gt;
&lt;li&gt;-F fs            : Use fs for the input field separator .&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Examples:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Using Awk to print every line from a specified file :
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ awk '{print}' &amp;lt;filename&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Printing the lines which match the given pattern in the specific file :
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ awk '/pattern/ {print}' &amp;lt;filename&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;For splitting Line Into Fields :&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The awk command breaks each record, or line, into separate records that are by default separated by whitespace characters and stored in the $n variables . It will be saved in $1, $2, $3, and $4, accordingly, if the line contains 4 words. Furthermore, $0 denotes the entire line .&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ awk '{print $1,$2}' record.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Using the built-in NR variables for displaying the line number :
Consider the below example for displaying line number on every line in the text file .
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ awk '{print NR,$0}' &amp;lt;filename&amp;gt; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Using the built-in NF variables for displaying the last field :
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ awk '{print $NF}' &amp;lt;filename&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Using NR built-in variables to Display Lines in between range : &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Consider below example to print all the line details from 3 to 6 lines in the file .&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ awk 'NR==3, NR==6 {print NR,$0}' &amp;lt;filename&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For the given text file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$cat &amp;gt; a.txt

Anil      Bela    Clara
Tasha     priya   naina
Menaka    sita    krishn
Praveena  ram     dia
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Consider the below example To print the first item including the row number(NR) separated with ” – “ from each line in a.txt :
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ awk '{print NR "- " $1 }' a.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;1 - Anil
2 - Menaka
3 – Menaka    
4 - Praveena
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;To return the second column/item from a.txt: &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Consider the below exapmple to return the second column/item from a.txt :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ awk '{print $2}' a.txt 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Bela
priya
sita
ram
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Printing a non-empty line :
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;awk ‘NF == 0 {print NR}’  &amp;lt;filename&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;awk ‘NF &amp;lt;= 0 {print NR}’  &amp;lt;filename&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt; To count the lines in a file :
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$ awk 'END { print NR }' &amp;lt;filename&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>crypto</category>
      <category>cryptocurrency</category>
      <category>blockchain</category>
      <category>web3</category>
    </item>
  </channel>
</rss>
