Python (A High Level Programming Language)




Python is an interpreted high-level general-purpose programming language. Python's design philosophy emphasizes code readability with its notable use of significant indentation. Its language constructs as well as its object-oriented approach aim to help programmers write clear, logical code for small and large-scale projects. 
Python is dynamically-typed and garbage-collected. It supports multiple programming paradigms, including structured (particularly, procedural), object-oriented and functional programming. Python is often described as a "batteries included" language due to its comprehensive standard library.


BASICS OF PYTHON

DISPLAYING TEXT ON SCREEN

To display text on screen using python, we use print command. For example my name is Yash Vardhan so to display my name using python I will write the following code.

print("My name is Yash Vardhan")

This line of code prints My name is Yash Vardhan. Print command displays the text which is there in " " (double quotes). We give brackets after print command because it is the syntax of python programming language. Python displays text when we will write text in double quotes otherwise it will give an error.

Output

My name is Yash Vardhan


ADDING, SUBTRACTING, MULTIPLICATING AND DIVIDING TWO OR MORE NUMBERS

To add, subtract, multiply and divide two or more numbers also we use print command but here to calculate two or more number we don't use " " (double quotes) because if we will use double quotes the it will display the numbers that we want to calculate.

Example

Code

print("2+3")

Output

2+3

To add two or more numbers we will remove the double quotes.

Adding Two Numbers

Code

print(2+3)

Output

4

Here, we are able to write code without double quotes because the value of these numbers is known. If you want to add three or four numbers then add them.

Example

print(2+3+4)

Output

9

Subtracting Two Numbers

Code

print(3-2)

Output

1

Multiplicating Two Numbers

print(3*2)

Output

6

Dividing Two Numbers

Code

print(6/2)

Output

3

Adding Comments

We can add comments to our code when we are giving our code to anyone else so that he can understand that what is the work of a particular function. Comments are lines that we write in our code but are not displayed in our code. In python We write comments by giving a #. There are two types of comments:-

  • Single lined comments : These are written by giving # symbols
  • Multi lined comments : These are written by giving ''' ''' symbols

Example

Single Lined Comment

# My name Is Yash Vardhan

Multi Lined Comment

'''Yash Vardhan'''

Storing Values In Variables

We can store values in variables. It is useful when we have to define something and get the value.

a = 2
b = 3
print(a+b)

Here a = 2 and b = 3 so a+b = 2+3

Output

5

Questions

  1. Write a program to calculate the sum of 6725 and 6256.
  2. Make a program and in that make any two variables and in that store any two valued and add them.
Comment me down that you have done the questions or not.

Post a Comment

0 Comments