Python: Hello World

Python: Hello World

Welcome to the world of programming! Let's kick things off by exploring Python through the classic Hello World program and some basic operations that highlight what makes Python so versatile.

Hello World Program

Step 1: Open a text editor or an integrated development environment (IDE) like PyCharm, Visual Studio Code, or IDLE.

Step 2: Create a file with a .py extension, such as hello_world.py and type the following code.

print("Hello World!")

Hello World!

Step 3: Save the file hello_world.py and Run It.

Step 4: If You don't get run button then ,Open a terminal or command prompt.

Step 5: Navigate to the directory where you saved hello_world.py using the cd command.

Step 6: Type python hello_world.py and press Enter.

You should see the output Hello World! printed on the screen.

Congratulations, you've just run your first Python program!

After seeing the output "Hello World!" printed on the screen, you've successfully executed your first Python program.

In Python, the print function is used to display information or output on the screen.

Syntax:

print("Text to be displayed")

Here, Text to be displayed can be any text enclosed in quotes (either single or double quotes).

Another Example

print(15)

15

print statement will simply print the number 15

print("The number is:", 15)

The number is: 15

we print the text The number is: followed by the number 15.

This demonstrates how you can combine text and numbers within a single print statement to create more informative output.

Certainly! In Python, when you're working with strings (text), you enclose the text within double quotes (" "). For numbers, particularly integers and floating-point numbers, you do not need to enclose them within quotes.

For Example:

print("Whole number:", 10)

print("Decimal number:", 3.14)

Whole number: 10

Decimal number: 3.14

In Python, you have the flexibility to perform simple mathematical operations directly in your code.

Each operation is performed directly within the print statement to show the result immediately.

print("Addition:", 10 + 5)

print("Subtraction:", 20 - 8)

print("Multiplication:", 5 * 4)

print("Division:", 20 / 4)

Addition: 15

Subtraction: 12

Multiplication: 20

Division: 5.0

Now that you've explored these basic operations, I encourage you to continue your coding journey.

Happy Coding !!!

You can support me by buying me a coffee ☕

Did you find this article valuable?

Support Ajay Sharma by becoming a sponsor. Any amount is appreciated!