CBSE CS and IP

CBSE Class 11 & 12 Computer Science and Informatics Practices Python Materials, Video Lecture

Showing posts with label Class 11 IP. Show all posts
Showing posts with label Class 11 IP. Show all posts

Comments (Single/Multiline) in Python

Comments (Single/Multiline) in Python


DataCamp

What is Comment in Python?

Any remark such as who made the code and the purpose in the form of a note can be added in the program using comments. Comments are not executed by the interpreter, they are added with the purpose of making the source code easier to understand by humans. The documentation of the code is done with the help of comments in the program itself. 

Comments are the additional readable information to clarify the source code, which is read by the programmers but ignored by the Python interpreter.

Why it is important to use Comments?

Whenever developers make a program, gradually so many codes are written in the same file for the different types of functionality. If commenting is not proper,  after some time, we do not understand our own code. We will face difficulty in understanding the codes written in our own program. So to easily understand the same problem, we use comments.
When you are working on a project with your team, it is necessary to use comments so that other programmers can understand what you have done in the source code by looking at the comment.
Using comments in our code makes our code easier to understand.

How do you write comments in code?

  • Comments are used to explain the code, which code is written for which work.
  • Comments are not part of the program, yet it is most useful for understanding the code.
  • Single line comments in Python begin with a symbol # (hash character) and generally end with the end of the physical line. (A physical line is the one complete line that you see on a computer whereas a logical line is the one that python sees as one full statement).
  • Multiline comments can be used in a program by simple put our text inside triple double-quotes (" " ") or triple single-quotes  (' ' '). Comments enclosed with triple quotes are called Docstring (Document String)

How many types of Comments?

Python has two types of comments, which are given below -:
  1. Single-Line Comments
  2. Multi-Line Comments

Single-Line Comments

In Python, Single line comments start with (#) symbol. 
If we put a # symbol at the starting of any line, then that line will be treated as a comment line. This line will not execute at the execution time, interpreter simply ignores it.
Example -: A single line comments in the program
# Single Line Comment
# Single Line Comment 

Multi-Line Comments

Multi-line comment in python code in two ways  -:
  1. Add a # symbol at the beginning of every physical line part of the multi-line comments.
  2. Type comment as a triple quoted multi-line string. This type of comment is also known as the docstring. You can either use a triple single-quote (' ' ') or triple double-quotes (" " ") to write a docstring. 
Example -: A Multi-line comments in the program
'''
This is a multiline Comment
This is a multiline Comment
This is a multiline Comment
'''
"""
This is a multiline Comment
This is a multiline Comment
This is a multiline Comment
"""


Benefits of using Comments in Python?

  1. The code can easily be understood when using comments.
  2. Makes code readable and understandable.
  3. Using Comments, we remember why we used this code.
  4. If the program is opened in the future, then there is no problem in understanding the code.
  5. Using comments gives the programmer an idea as to why they are using this code.


Data Types In Python

Data Types in Python

In this post, I am going to discuss various types of data that you can store in Python. The data can be stored in mutable or immutable types of variable.

Let us now discuss CBSE class 11 subject Informatics practices and Computer Science chapter Data Types in Python.

What is Data type?

A data type or simply a type is a property of data, that tells the language processor (compiler, interpreter) how we are going to use this data. 
  • Data types tell the meaning of data, how that data is going to store in memory and what different operations can be performed on it. 
  • In the Python programming language, if we have to store any value in a variable, then the data type role comes into play.
  • when we are storing a value in a variable, we have to use the same types of data as the type of variable. Each value belongs to some data type in Python.
  • Data type identifies the type of data which a variable can hold and the operations that can be performed on those data.

Mutable vs Immutable Data Types

Mutable:- Mutable data types are objects whose value can be changed once it is created. This type of object allows changing the value in place.
Ex:- List, Dictionary, Set
1
2
3
4
5
6
7
8
>>> v = 10
>>> type(v)
<class 'int'>
>>> id(v)
140731797110112
>>> v = 20
>>> id(v)
140731797110432                                                 

Immutable:- Immutable data types are objects whose value cannot be changed once it is created. 
Ex:- int, float, bool, string, tuple
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
>>> l = [1,2,3]
>>> type(l)
<class 'list'>
>>> id(l)
2413299978760
>>> l[0] = 99
>>> l
[99, 2, 3]
>>> id(l)
2413299978760                                                      

Data Types In Python -:

There are many data types available in python like character, integer, real, string, etc.

Before you learn how can process different types of data in Python, let us discuss various data types supported by Python. Everything in the Python programming language is an object, the data types are actually classes and variables are objects of these classes. 

Python offers the following built-in core data types -: 
  1. Numbers
  2. String
  3. List
  4. Tuple
  5. Dictionary
See the description of these data types in the following table:


S. No. Data types Description
1 Numbers Integer Number-:
-It is of unlimited range, which depends on the availability of memory.
-We can not use the Decimal number in it.
Example -: 5, 32, 1876,0
Boolean Value -:
Two value TRUE (1) / FALSE (0)
Floating Point Number -:
-It is of unlimited range, range depends upon the memory in the machine architecture.
-It is used to store a decimal number.
Example -: 5.0, 32.0
Complex Number -:
Same as floating-point numbers, because the real and imaginary parts are represented as floats.
Example-: A+Bj
2 String It is a sequence of Unicode characters.
It can hold any type of known characters, like letters, numbers.
It is a derived data type.
Example-: 'abcd', '1234', '????'
3 List It represents a list of comma-separated values of any datatype between square brackets.
It is a compound data types.
The list is changeable means one can change/add/delete the elements of a list.
Example -:[1, 2, 3, 4] ['a', 'b', 'c', 'd']
4 Tuple the tuple is immutable/non-changeable that means one can not make a change to a tuple.
Example :
p= (1, 2, 3, 4,5)
q = (2, 4, 6, 8)
r = ('a', 'b', 'c', 'd')
r = ('2', '5', '7', 'a', 'b', 'c')
5 Dictionary It is in an unordered set of comma-separated key: value pairs.
No two keys can be the same (unique keys within a dictionary).

The type() function is used to check the data type

Numbers

As it is clear by the name the number data types is used to store numeric values in Python, which means Number data type stores only numerical values.

When a number is assigned to a variable, then Python creates an object of Number Class.

Now, we will understand which numeric data type does Python support. We will tell you about it below -:
  1. Integer Numbers
  2. Boolean data type
  3. Floating Point Numbers
  4. Complex Numbers

Integer Numbers -:

  • Integers are whole numbers such as 2, 43, 2356, 0, etc.
  • They do not have any fraction parts. In Python, Integers are represented by numeric value with no decimal point.
  • Integers can be positive or negative. Positive numbers are represented with a + (plus) sign, and negative numbers are represented by - (minus) sign.
  • Integers in Python 3.x can be of any length, it is limited by the memory available. Python provides single data type integer to store an integer, whether big or small.
Example -:

## var1 is an integer variable
var1 = 10
type(var1)

##Output
<class 'int'>

Boolean Value -:

Just like in real life some questions are answered in yes or no, similarly, the computer also gives answers in yes or no. To store this type of value in a computer, we use boolean data type. A boolean value is represented by True or False.
  • It represents the value only in True and False.
  • The boolean type is a subtype of plain integers.
  • True and False behave like (1) and (0).
  • When user type bool(0) or bool(1), Then Python will return a value False and True respectively. bool(0) will always give False. Any number other than 0, weather +ve or -ve will give True if passed inside bool().
  • There is no conversion between the Boolean Data Type and Integer Data Type. 
  • We can directly use Boolean value True/False in any kind of conditional statement.
Example -:
## var1 and var2 is an boolean variable
var1 = True
type(var1)   ##Output: <class 'bool'>

var2 = False
type(var2)   ##Output: <class 'bool'>

Floating Points Number -:

If we have to declare the variables in our program which are to be used to stores decimal numbers, then we declare such variables as a float data type. 
  • A number which has some parts as fractional is called floating-point number.
  • The decimal point (i.e. a dot ".") signals that this number is a floating-point number, not an Integer.
  • Floating numbers can be positive or negative.
  • Floating points variables represent real numbers. Which are used for measurable quantities like distance, area, temperature, etc. and typically have a fractional part.
  • Floating numbers represent machine-level double precision floating point numbers (15 digit precision). 

Advantage-:

  • They can represent a value between the Integers.
  • We can represent a large range of values using it.

Disadvantage -:

  • Floating points operations are usually slower than integer operations.
Example -:
## var1 is a floating type variable
var1 = 5.75
type(var1)   ##Output: <class 'float'>

Complex Number -:

  • Python represents complex numbers as a pair of floating-point numbers.
  • A complex number is a composite quantity made of two parts -: the Real part and the Imaginary part. Both of which are represented internally as Float values (floating-point numbers).
  • A complex number consists of both real and imaginary components.
  • In complex number A + Bi. where  A is a real number and B is an imaginary part. i is used for denoting the imaginary part.
Example -:
## var1 is a complex data type variable
var1 = 3 + 5j
type(var1)   ##Output: <class 'complex'>

var1.real    ##Output: 5.0
var1.imag    ##Output: 3.0


String Data type

The string is written within a single(' ') or doubles (“ “) quotes.


When we provide information to the user, then the information is always represented as a group of characters, the group of characters is called String.

In Python 3.x, each character stored in a string is a Unicode character, which means all string in Python 3.x is a sequence of pure Unicode characters. Unicode is a system which is designed to represent every character from every language.


  • A string is the Group of characters. These characters may be digits alphabets or special characters including spaces.
  • A string data type lets you hold string data like any number, of valid characters into a set of quotation (" ")  marks.
  • A string can hold any type of known characters like letters, numbers, and special characters.
Following are string in python

'abcd' , '1234'

Example -:

## var1,var2,var3 are string data type variables

## with double quotes
var1 = "Hello"
type(var1)     ## <class 'str'>

## with single quotes
var2 = 'Hello'
type(var2)     ## <class 'str'>

var3 = '12345'
type(var3)     ## <class 'str'>




List Data type


A list is an important data type of Python. Many values are kept in it. Each value is separated by a comma, And all the values are placed inside a square bracket {'[', ']'}.

  • A list is a python compound data type. It can have different data types of data inside it.
  • Lists can be changed/modified/mutate. This means List is a Mutable Data type.
  • A list in python represents a comma-separated value of any datatype between the square bracket.
Example -:
## var1,var2,var3 are list data type variables

## with similar data type variables 
var1 = [1,2,3,4]
type(var1)     ## <class 'list'>

var2 = ['A','B','C','D']
type(var2)     ## <class 'list'>

## with different data type variables
var3 = ["Hello",1,2,3.5]
type(var3)     ## <class 'list'>


Tuples Data type

  • A tuple is a sequence of items separated by commas and items are enclosed in parenthesis { '(' and ')'}. This is unlike the list, where values are enclosed in square brackets {'[', ']'}.
  • The difference between List and Tuple is that the Tuples can not be changed or modified once created. That means we can not change items in the tuple. The similarity to a list is that the items of Tuples may be of different data types.
Example -:
## var1,var2,var3 are list data type variables

## with similar data type variables 
var1 = (1,2,3,4)
type(var1)     ## <class 'tuple'>

var2 = ('A','B','C','D')
type(var2)     ## <class 'tuple'>

## with different data type variables
var3 = ("Hello",1,2,3.5)
type(var3)     ## <class 'tuple'>


Dictionary

Tokens In Python


Tokens In Python



Tokens in Python -:

Today we will discuss "Python tokens", "Types of tokens with example", "List of tokens in Python", "How many types of tokens are allowed in Python".The Smallest individual unit in a python program is known as "Tokens".Python has mainly 5 types of token which are given below -:
  1. Keywords
  2. Identifiers
  3. Operators
  4. Literals 
  5. Punctuators 

Keywords in Python

What are the keywords in Python??

Keywords are the reserved word having special meaning and purpose in Python. Keywords cannot be used as an identifier name such as any variable name or Function Name. They are used to defined "Syntax" or "Structure" of the Python language. Python Keywords are case sensitive.

Python keywords is a special word, that forms the vocabulary of the python language. It is a reserved word that can not be used as an identifier.

How many keywords are there in Python??

There are as many as 33 keywords are used in Python programming language version 3.7. Keyword builds the vocabulary of the python language, they represent the "syntax and structure" of a python program.

How do you find a keyword in Python??

Following is the list of keywords in the python, there are 33 Keywords:

S No Keywords Description
1 and A logical operator
2 as To create an alias
3 assert For debugging
4 break To break out of a loop
5 class To define a class
6 continue It skips the remaining part of the loop and goes to the next iteration
7 def To define a function
8 del To delete an object
9 elif Used in conditional statements, same as else if
10 else Used in conditional statements
11 except It is used with exceptions. this part will execute if an exception occurs.
12 FALSE Boolean value, the result of comparison operations
13 finally It is used with exceptions. It executes irrespective of exception occurs or not
14 for To create a for loop
15 from To import specific parts of a module
16 global To declare a global variable
17 if To make a conditional statement
18 import To import a module
19 in To check if a value is present in a list, tuple, etc.
20 is To test if two variables are equal
21 lambda To create an anonymous function
22 None Represents a null value
23 nonlocal To declare a non-local variable
24 not A logical operator
25 or A logical operator
26 pass It is a "do nothing" statement. 
27 raise To raise an exception
28 return To exit a function and return a value
29 TRUE Boolean value, result of comparison operations
30 try To make a try...except statement
31 while To create a while loop
32 with Used to simplify exception handling
33 yield To end a function returns a generator
  

Identifier in Python

Before knowing Python Identifiers, we will learn what is Identity?? 

Identity is a property that makes a person different, it may be personality looks or expressions. Same way, Python identifier is the same as the identity of a Person.

Names given to a Class, Function or Variable is called Identifier in python. It helps to differentiate one entity from others.

What are the rules for identifiers??

  1. Identifier first letter should be any letter or underscore(_).
  2. Upper and lower-case letters are different.
  3. The digit 0 through 9  can be part of the identifier except for the first character.
  4. It should not be a keyword (list of 32 keywords discussed above).
  5. An identifier can not contain any special character except for underscore (_).

Valid / Invalid  Identifiers Examples -:

Valid Identifier -:  Mybook, file 123, z2td, _no
Invalid Identifier  -: 2rno , break , .mybook

Let us discuss why the given identifiers are Invalid.

  • 2rno: It is starting with a number
  • break: It is a Keyword
  • .mybook: It is containing "." keyword.  

Operators in Python

Operators are tokens that trigger some computation/action when applies to variables and other objects in an expression. Variables and objects to which the computation is applied are called operands.

There are following types of Operators:
  1. Arithmetic Operators
  2. Relational Operators
  3. Assignment Operators
  4. Logical Operators
  5. Bitwise operators
  6. Membership Operators
  7. Identity Operators

Arithmetic Operators -:

  • Arithmetic Operators are used to performing arithmetic operations like Addition, Subtraction, Multiplication, division etc.
  • There are following types of Arithmetic Operators in Python:
    Operators Description Example
           + perform addition of two number a+b
            - perform subtraction of two number a-b
            / perform division of two number a/b
            * perform multiplication of two number a*b
            % Modulus = returns remainder a%b


Relational (Comparison )Operators -:

  • Relationa operators perform an operation on data and return the result in Boolean true or False.
  • Relational Operators are used to comparing the value and decide the relation among them.
 Operators Description Example
      == True if a is equal to b a == b
      != True is a is not equal to b, otherwise False a != b
       > True if a is greater than b, otherwise False a>b
      >= Greater than or equal to, return true if a is greater than b or a is equals to b a>=b
       < True if a is less than b, otherwise False a < b
     <= Less than or equal to, return true if a is less than b or a is equals to b a<=

Assignment Operators -:

  • Assignment Operators are used to assigning value to a variable.
  • There are following types of assignment operators are there in Python:
Operators Description Example
      = Right side value will be assigned to the left side. a=b
    += both the operands will be added and result will be assigned to the left side operand. a+=b
     /= left operand divided by right operand, the result will be assigned to the left side operand a/=b
     *= both the operands will be multiplied and the result will be assigned to the left side operand. A*=b
     -= left operand minus right operand, the result will be assigned to the left side operand A-=b
    %= left operand modulus right operand, the result will be assigned to the left side operand a%=b
    //= left operand floor divide right operand, the result will be assigned to the left side operand a//=b
   **= the left operand to the power of right operand, the result will be assigned to the left side operand. a**=b

Logical Operators -:

  • Logical operators are used with conditional statements that can be TRUE or False.
  • Logical Operators are used to performing logical operations on the two given variables or values.
  • and, or and not are logical operators.
Operators Description Example
    and return true if both conditions are true x and y
     or return true if either or both condition is true x or y
     not reverse the condition not(a>b)

Bitwise Operators -:

  • Bitwise Operators acts on operands as if they were string or binary digits. They operate bit by bit hence its name is bitwise Operator.
Operator Meaning Example
          & Bitwise AND x & y = 0 (0000 0000)
           | Bitwise OR x | y = 14 (0000 1110)
           ~ Bitwise NOT ~x = -11 (1111 0101)
           ^ Bitwise XOR x ^ y = 14 (0000 1110)
         >> Bitwise right shift x >> 2 = 2 (0000 0010)
        << Bitwise left shift x << 2 = 40 (0010 1000)

Membership Operators -:

  • The Membership operators are used to validate whether a value is found within a sequence such as string, lists or tuples.

  • Operators Description Example
          in return true if a value exists in the sequence, else false. a in list
       not in return true if the value does not exist in the sequence, else false. a not in list

Identity Operators -:

  • Identity operators are used to comparing the memory location of two objects. 
    Operators Description Example
    is returns true if two variables point the same object, else false a is b
    is not returns true if two variables point the different object, else false a is not b


Literal (Value) in Python

  • Literals like a constant (often referred to as constant - values) are data items that have a fixed value.
  • Literals yields an object of the given type (String, integer, Long integer, Long floating number, Complex number ) with the given value.
    Python allows several kinds of literals.
    1. String Literals
    2. Numeric Literals
    3. Boolean Literals.

SN Literal Name Description
1 String Literal A string literal is a sequence of characters surrounded by quotes (single or double or triple quotes)
Example-: 'a' , 'abc' , "abc"
2 Numeric Literal 1. int (signed integers) -: No decimal points.
Example -: age=22
2. float (floating point real values) –: represent real number & written a decimal point.
Example -: height = 5.2
3. complex (complex numbers)
Example-: name = None
3 Boolean Literal 1. true (Boolean Literal)
2. false (Boolean Literal)

Punctuators  in Python

  • Punctuators is used to implement the grammar and structure of syntax. 
  • Punctuators are symbols that are used in a programming language to organize programming sentence.
The most common punctuators of Python programming language are:-  

| ' " # \ [ ] : ; =
( ) { } @ <<= >>= **= %= &=

How To Download and Install Python

Python Installation on Windows


DataCamp

In this post, I am going to discuss How to install Python (32 bit / 64 bit) in your computer (Windows 10 OS, Windows 7). To install the python you have to download the python from python.org. Python is free and Open-source. You can also find its source code on the internet.

In this website you will find the different versions of the Python, so you have to choose the latest version every time.

Step 1:- 

  1. Firstly click on this link Download Python.
  2. Now you will see this web Page:
python.org

Step 2  (Download for 32-bit Windows):-

  1. Now click on the "Download" option.
  2. Now you will find "Download for windows"  click on"Python 3.*.*" (Latest Version).
How to install python

Step 3 (For 32 Bit Operating System):-  

  1.  After the click , you can see on .exe file is downloading.
How to install python

Step 3 (For 64-bit Operating System)-:

  1. If you want to download Python for "64-bit windows" then scroll down in the page then you will find heading files. Then click on this link "Windows x86 64 executable installer".
  2. This will download a 64 bit Python installer.

How to install python


Step 4 

  1. Click on the Installer.
  2. Now, you can see pop up Window, so click Yes the button.

step 5:-

After clicking Yes, you will see the window as shown below. Tick "Add Python 3.* to Path". This will help you access python from anywhere in your windows OS.  

How to install Python

Step 6:-

Now you will find that the Python is installing. Let the Installation finish.
How to install python


Step 7:- 

After Successful installation, you will get the following message. That means the Python installation is successful. 
How to install Python

Step 9:-

Now you can go to start and search Python, you will find the python in your windows. Now you can access the Python from there.
How to install Python





Language Processors in Python



PYTHON LANGUAGE PROCESSORS


Today, we will tell you to class 11 and class 12 subjects computer science and informatics practices topic a "language processor" in the basics of Python. There are two types of languages in terms of computers. One which is near to the computer is called Low-Level Language and One that is near to human is called High-Level Language
  • High-level language (HLL) - When a programmer writes a program, he uses High-level language.
    Examples of High-Level Language:- C, C++, Java, Python etc.
  • Low-level language (LLL) - Computer understands the program in 0 and 1 binary code called machine language. A High-Level language can not be directly understood by a computer.
    Examples of Low-Level Language:- Machine Language, Assembly Language.
Since Computer understands Machine Language, hence there is a need to convert High-Level Language (Ex:- Python) to Low-Level Language (Ex:- Machine Language). For this purpose, Language Processors are used. 

Language Processors are programs that convert the High-level language (source code) into Low-Level Language (machine code). Language Processors are also called Language Translators

Before going further, you must know the following terms:
  • Language Translator -: A program that transforms a high-level computer language to Machine Language is called a computer Language Translator. 
  • Source Code -: A Source code is a high-level language that is understandable by us, humansThe computer language in which the original Program is written is called Source Language.
  • Object Code -:  An Object Code is a Low-Level Language that is understandable by Computer. The Object Code is also Called Byte Code or Binary Code because it is in binary (0/1) form.
  • Machine Code -: Machine Code is also in binary (0/1) form and is a Low-Level Language. But is different from Object code. It is machine-specific. Linker produces executable machine code on a particular machine using Object Code.
  • Assembly Language-: It is a Low-Level Language. But, it is different from the Object Code or Machine Code. It has the instruct actions in the form of coding, which is converted to Machine language before execution.
    Example of Assembly Language code to add two numbers:-
    mov reg1 , 3
    mov reg2 , 4
    add reg1 , reg2 , reg3

Types of Language Processor / Language Translator

There are three different types of Language Processors or Language Translators:
  1. Assembler
  2. Compiler
  3. Interpreter
Let us now discuss each one by one.

1. What is Assembler?

An Assembler converts "assembly language"  into "Machine language". Assembly language Program has its own syntaxes and can be written by Computer Programmers.

2. What is a Compiler?

A compiler is a translator that converts "source code" (High-Level Language) into "Machine Language" (Low-Level Language) all at once. If there is an error in the Source Code, Nothing will execute.

A compiler is a group of one or more computer programs that transform programs written in the higher-level language into another language (Assembly or Machine Language). The compiler is used in a high-level programming language such as C, C++, java, etc.

C, C++,  java, etc. are High-Level Programming Language, these also need to be translated into machine language so that the computer can understand them. 

Decompiler -:

As the name suggests it is opposite to Compiler. Computer Programs that produce a high-level language program by collocating a low-level computer language program are called Decompiler. 

3. What is an Interpreter?

The interpreter is used for converting a "high-level language" code into "Machine Language" code line by line. If an error occurs in any line, it stops there and does not proceed until that error is corrected. 

An interpreter is a computer program that is used to run instructions written in a programming language code line by line. It translates program line by line at a time. The interpreter is used with programming languages like Python, Ruby, javascript, etc.


Difference Between Compiler & Interpreter




CompilerInterpreter
It converts high-level language code to machine code in one session.It converts high-level language to machine language.
The compiler translates the entire program.The interpreter reads line by line program,
It takes time because it has to translate high-level code into low-level code.It works as a compiler for translating programming code to machine code, but it reads the code line by line and immediately executes it.
The compiler needs more memory than an interpreter.The interpreter needs less memory than the compiler.
It is initially slower than an Interpreter.It is initially faster than a compiler.
Compilers take a large amount of time to analyze the source code.An interpreter analyses the source code in less amount of time.
The overall execution time of the compiler is faster than interpreters.Overall execution time is comparatively slower than interpreters.
Translate the program as a whole-time into machine code.Translate program one statement at a time.
No intermediate object code is generated.Generates an intermediate object code.
If there is an error in the program then it shows in last.If there is an error in any line, first it corrects that error then moves ahead. It Is converting and executing the program line by line.
Debugging in a Compiler is not easy.Debugging in Interpreter is easy.
It is used in a programming language like Python, Javascript, Ruby, etc. It is used in a programming language like C, C++, Java, etc.
Compiled code run fasterInterpreted code run slower.


How does a Compiler & Interpreter work?

Compiler and Interpreter both convert High-Level Language to Low-Level Language. Then you will have questions then what is the difference between interpreter and compiler.

The main difference between compiler and interpreter is that compiler converts High-level language (Source Code) to Low-Level Language (Object Code) at once and the Interpreter converts High-level language (Source Code) to Low-Level Language (Object Code) Line by Line.

The compiler takes the full source code and makes the Binary Code or Object Code at once if there is an error in the program then none of the lines will execute.

In the case of the Interpreter, it takes the source code line by line and converts it into Object code then executes it. For example, if  I have 1000 lines of code and line number 501 is having some syntax error, then all the statements till line number 500 will be executed and the program will give an error at line number 501.

Python Modes

Here we are going to learn about two basic modes of Python:-
  1. Interactive Mode
  2. Script Mode

Interactive Mode -:

  1. Interactive mode is used for running a single line or single block of code.
  2. Interactive mode runs very quickly and gives the output instantly.
  3. Editing the written code is a tough task in interactive mode.

Script Mode  -:

  1. Script mode is used to work with lengthy codes or multiple blocks of code.
  2. Script mode takes more time to compile and run.
  3. Script mode gives flexible editing options.

How to run Python in Interactive Mode

To run Python in interactive mode follow the given steps:
  • Step 1 - Go to Start and search "Python"

    Interactive Mode in Python


  • Step 2 - It will show the installed python black command prompt window. Open it

    Python command prompt window


  • Step 3 - You can now start working on it.

How to run Python in Script Mode

To execute the python program in Script Mode follow the following steps:
  • Step 1 - Go to Start and Search "Python"

    Python Script Mode

  • Step 2- Here you will find IDLE Python with your installed Python version.

    Python script mode.png

  • Step 3 - Now under this IDLE (Integrated Development Environment), you will find the option file. Using this you can create a Python Script (program) and save it with the ".py" extension.

    Python script mode

  • Step 4 - In the same window, there is Option Run. After writing the Full Python Program you can run your program by clicking this menu button.