Python

 12| 3| 4| 5| 6| 7| 8| 9| 10

Page 1

Programming

Before starting with python, we need to understand what Programming is? Programming is a technique of solving a computational problem in a particular language usually in a high-level language like Java or Python. 
The program is constructed by converting the algorithm (step-by-step solution) into its equivalent programming code. For example, if we use python, then we will write code in python language and will give a solution to a specific problem. 


Object Oriented Programming


Now, we should understand what is Object Oriented programming is. Python is an object-oriented programming language. it means all the concerned data will be an object for python. the object can be related to a real-time entity like a box, a car, a dog, etc.


Execution Modes of Python

There are two ways to use the Python Interpreter-
a) Interactive Mode
b) Script Mode


Interactive Mode-

To work in the interactive mode, we can simply type a
Python statement on the >>> prompt directly. As soon as
we press enter, the interpreter executes the statement
and displays the result(s),


Script Mode-

In the script mode, we can write a Python program in
a file, save it and then use the interpreter to execute it.
Python scripts are saved as files where the file name has
the extension “.py”.

To Run the program, we need to go to the Run->Run Module


PYTHON KEYWORDS


These are the reserved words for Python. Python interpreter knows the special meaning of a particular keyword. A few Python keywords are provided below-

if, else, True, False, in, for, while, class, etc. 


VARIABLES

A variable in a program is uniquely identified by a name (identifier). Variable in Python refers to an object — an item or element that is stored in the memory.
Example-
x="hello"
Here x is the variable and String "Hello" is stored in variable x.
y=2
Here y is variable and Integer 2 is stored in variable y

Program 5-2 Write a program to display the values of variables in Python.


message = "Keep Smiling"
print(message)
userNo = 101
print('User Number is', userNo)


Output-
Keep Smiling
User Number is 101

COMMENTS IN PYTHON


Sometimes, we need to add a few words or lines that we don't want the python interpreter to do anything. These are used just to increase the readability of the python program. 
Example-

#This is Addition program
a=3
b=4
c=a+b
print(c)


In the above program, the first line #This is an addition program that will not be read by the python interpreter. To start a comment, we should use the # symbol.  



 12345678910

No comments:

Post a Comment