Your First Python Program


Often, a program called "Hello, World!" is used to introduce a new programming language to beginners. A "Hello, World!" is a simple program that outputs "Hello, World!".
However, Python is one of the easiest language to learn, and creating "Hello, World!" program is as simple as writing print("Hello, World!"). So, we are going to write a different program.

Program to Add Two Numbers

How this program works?

Line 1: # Add two numbers
Any line starting with # in Python programming is a comment.
Comments are used in programming to describe the purpose of the code. This helps you as well as other programmers to understand the intent of the code. Comments are completely ignored by compilers and interpreters.
Line 2: num1 = 3
Here, num1 is a variable. You can store a value in a variable. Here, 3 is stored in this variable.
Line 3: num2 = 5
Similarly, 5 is stored in num2 variable.
Line 4: sum = num1+num2
The variables num1 and num2 are added using + operator. The result of addition is then stored in another variable sum.
Line 5: print(sum)
The print() function prints the output to the screen. In our case, it prints 8 on the screen.

Few Important Things to Remember

To represent a statement in Python, newline (enter) is used. The use of semicolon at the end of the statement is optional (unlike languages like C/C++, JavaScript, PHP). In fact, it's recommended to omit semicolon at the end of the statement in Python.
Instead of curly braces { }, indentations are used to represent a block.
   im_a_parent:
    im_a_child:
        im_a_grand_child
    im_another_child:
        im_another_grand_child

If any query regarding this topic then comment below.


Thank you :)

Comments

Popular posts from this blog

Python Matrix

Angular : List of Topics

What are the steps involved in the concreting Process?