Skip to main content

Python print() Function

When you start learning Python, one of the first things you need to learn is how to display information on the screen. For example, you might want to display: A welcome message. Your name and age. The result of a mathematical calculation. Student marks and results. Information generated by a Python program. Python provides a built-in function called print() for displaying information. The print() function is one of the simplest and most frequently used functions in Python. It helps programmers display information while testing programs, solving problems, and developing applications. In this article, we will learn how to use print() with practical examples and their outputs. 1. What Is the print() Function in Python? The print() function is a built-in Python function that displays information in the output area, usually the terminal or console. Let's look at a simple example. print("Hello, World!") Output: Hello, World! In this example, Python displays the text Hello,...

HTML Headings, Paragraphs, and Text Formatting

After learning how to create and run an HTML webpage, the next step is understanding how to display and format text properly.

Text is one of the most important parts of any webpage. HTML provides different tags for:

  • Headings

  • Paragraphs

  • Line breaks

  • Horizontal lines

  • Text formatting

In this article, we will learn all these concepts in detail with examples.


HTML Headings

Headings are used to define titles and subtitles on a webpage.

HTML provides six heading tags.

<h1>Heading 1</h1>
<h2>Heading 2</h2>
<h3>Heading 3</h3>
<h4>Heading 4</h4>
<h5>Heading 5</h5>
<h6>Heading 6</h6>

Output Explanation

TagSize
<h1>Largest
<h2>Smaller than h1
<h3>Medium
<h4>Smaller
<h5>Very small
<h6>Smallest

Example Program

<!DOCTYPE html>
<html>

<head>
    <title>HTML Headings</title>
</head>

<body>

    <h1>Main Heading</h1>
    <h2>Sub Heading</h2>
    <h3>Section Heading</h3>
    <h4>Small Heading</h4>
    <h5>Very Small Heading</h5>
    <h6>Smallest Heading</h6>

</body>

</html>

Importance of Headings

Headings help:

  • Organize content

  • Improve readability

  • Improve SEO

  • Help search engines understand webpages

Search engines like Google use headings to analyze webpage structure.


Best Practices for Headings

Use Only One <h1> Per Page

The <h1> tag should represent the main title.

Example:

<h1>Introduction to HTML</h1>

Use Headings in Sequence

Correct:

<h1>Main Title</h1>
<h2>Sub Title</h2>
<h3>Topic</h3>

Wrong:

<h1>Main Title</h1>
<h4>Topic</h4>

HTML Paragraphs

Paragraphs are created using the <p> tag.

Syntax:

<p>This is a paragraph.</p>

Example Program

<!DOCTYPE html>
<html>

<head>
    <title>Paragraph Example</title>
</head>

<body>

    <h1>About HTML</h1>

    <p>
        HTML stands for HyperText Markup Language.
        It is used to create webpages.
    </p>

</body>

</html>

Important Note About Paragraphs

HTML automatically removes extra spaces and line breaks.

Example:

<p>
Hello



World
</p>

Output:

Hello World

HTML Line Break Tag

To move text to the next line, use <br>.

Example:

<p>
Hello<br>
World
</p>

Output:

Hello
World

HTML Horizontal Rule

The <hr> tag creates a horizontal line.

Example:

<h1>HTML</h1>

<hr>

<p>HTML is used for webpage structure.</p>

Uses of Horizontal Rule

  • Separate sections

  • Improve webpage design

  • Organize content visually


HTML Text Formatting

HTML provides formatting tags for changing text appearance.


Bold Text

<b> Tag

<b>Bold Text</b>

Output:
Bold Text


Strong Text

<strong> Tag

<strong>Important Text</strong>

Difference:

  • <b> only makes text bold

  • <strong> indicates important content


Italic Text

<i> Tag

<i>Italic Text</i>

Emphasized Text

<em> Tag

<em>Emphasized Text</em>

Difference:

  • <i> → Visual italic

  • <em> → Semantic emphasis


Underlined Text

<u> Tag

<u>Underlined Text</u>

Marked Text

<mark> Tag

Highlights text.

<mark>Highlighted Text</mark>

Small Text

<small> Tag

<small>Small Text</small>

Deleted Text

<del> Tag

<del>Deleted Text</del>

Output shows a strike-through line.


Inserted Text

<ins> Tag

<ins>Inserted Text</ins>

Usually displayed with underline.


Superscript Text

<sup> Tag

Used for powers.

Example:

x<sup>2</sup>

Output:

x²

Subscript Text

<sub> Tag

Used in chemical formulas.

Example:

H<sub>2</sub>O

Output:

H₂O

Complete Text Formatting Program

<!DOCTYPE html>
<html>

<head>
    <title>Text Formatting</title>
</head>

<body>

    <h1>HTML Formatting Tags</h1>

    <b>Bold Text</b>
    <br><br>

    <strong>Important Text</strong>
    <br><br>

    <i>Italic Text</i>
    <br><br>

    <em>Emphasized Text</em>
    <br><br>

    <u>Underlined Text</u>
    <br><br>

    <mark>Highlighted Text</mark>
    <br><br>

    H<sub>2</sub>O
    <br><br>

    x<sup>2</sup>

</body>

</html>

HTML Preformatted Text

The <pre> tag preserves spaces and line breaks.

Example:

<pre>
Hello
     World
</pre>

Output keeps formatting exactly as written.


Why <pre> is Useful

Used for:

  • Poems

  • Code snippets

  • ASCII art

  • Structured text


Example Using <pre>

<pre>
Twinkle Twinkle Little Star
    How I Wonder What You Are
</pre>

HTML Quotations

Short Quotations

Use <q> tag.

<q>Knowledge is power</q>

Block Quotations

Use <blockquote>.

<blockquote>
HTML is the backbone of web development.
</blockquote>

Abbreviation Tag

Use <abbr>.

Example:

<abbr title="HyperText Markup Language">
HTML
</abbr>

When the mouse moves over the text, full form appears.


Address Tag

Used for contact information.

<address>
Kolkata, India
</address>

Nested Formatting Tags

Tags can be combined.

Example:

<b><i>Bold and Italic</i></b>

Real-Life Example Webpage

<!DOCTYPE html>
<html>

<head>
    <title>Student Blog</title>
</head>

<body>

    <h1>Welcome to My Blog</h1>

    <hr>

    <p>
        HTML is the <strong>foundation</strong>
        of web development.
    </p>

    <p>
        Learning <mark>HTML</mark> is very important.
    </p>

    <p>
        Water Formula: H<sub>2</sub>O
    </p>

    <p>
        Equation: x<sup>2</sup> + y<sup>2</sup>
    </p>

</body>

</html>

Common Mistakes Beginners Make

1. Forgetting Closing Tags

Wrong:

<b>Bold

Correct:

<b>Bold</b>

2. Using Too Many <br> Tags

Avoid excessive line breaks.


3. Using Headings for Styling Only

Headings should represent structure, not just size.


Advantages of Proper Text Formatting

  • Better readability

  • Improved webpage structure

  • Better SEO

  • Professional appearance

  • Improved accessibility


Conclusion

Headings, paragraphs, and formatting tags are the basic building blocks of webpage content. They help organize information clearly and make webpages easier to read.

Comments

Popular posts from this blog

Understanding Comments in Java: A Beginner’s Guide

When learning Java programming, one of the first concepts you’ll come across is comments . Comments may not affect how a program runs, but they play a crucial role in making code more understandable, readable, and maintainable. Let’s dive deeper into what comments are, why they’re important, and the different types of comments in Java. What are Comments in Java? A comment in Java is a piece of text written within a program that is ignored by the compiler . In other words, comments are notes for humans, not instructions for machines. They help developers explain the purpose of code, describe logic, or temporarily disable certain lines of code without deleting them. Why are Comments Important? 📌 Readability – Comments make code easier to understand for you and others. 📌 Maintenance – When you revisit your code after months, comments remind you what you were doing. 📌 Collaboration – In team projects, comments explain code to fellow developers. 📌 Debugging – You c...

Java Program to Check Voting Eligibility

In this program, we’ll take the user’s age as input and check whether the person is eligible to vote or not. In India, the minimum age required to vote is 18 years . 💻 Program Code // Java Program to Check Voting Eligibility import java.util.Scanner; public class VotingEligibility { public static void main(String[] args) { // Create Scanner object to take input from user Scanner sc = new Scanner(System.in); // Ask user to enter age System.out.print("Enter your age: "); int age = sc.nextInt(); // Check eligibility if (age >= 18) { System.out.println("You are eligible to vote."); } else { System.out.println("You are not eligible to vote yet."); System.out.println("You can vote after " + (18 - age) + " year(s)."); } sc.close(); // Close the scanner } } 🧠 Explanation import java.util.Scanner; → Imp...

Java Program to Calculate Total Marks and Average of Five Subjects

💡 Program Explanation In this program: The user will input marks of five subjects . The program will calculate the total marks and average . It will then display both results clearly. 🧑‍💻 Java Code: // Java Program to Calculate Total Marks and Average of Five Subjects import java.util.Scanner; // Importing Scanner class for user input public class TotalAndAverage { public static void main(String[] args) { // Creating Scanner object to take input from user Scanner sc = new Scanner(System.in); // Declaring variables for five subjects double subject1, subject2, subject3, subject4, subject5; // Taking marks input for each subject System.out.print("Enter marks of Subject 1: "); subject1 = sc.nextDouble(); System.out.print("Enter marks of Subject 2: "); subject2 = sc.nextDouble(); System.out.print("Enter marks of Subject 3: "); subject3 = sc.nextDo...