Class 11 Informatics Practices Ch 3 Brief Overview of Python NOTES with WORKSHEET

Chapter – 3 : Brief overview of Python – Basics (Notes and Worksheets)

Program :

An ordered set of instructions or commands to be executed by a computer is called a program.

Programming Language:

The language used to specify set of instructions to the computer is called a programming language for example Python, C, C++, Java, etc.

Python:

Python is a very popular and easy to learn programming language, created by Guido van Rossum in 1991.

It is used in a variety of fields, including software development, web development, scientific computing, big data and Artificial Intelligence

Download Python:

The latest version of Python is available on the official website:
https://www.python.org/


More –


Working with Python:

  1. Python Interpreter : Python interpreter is must be installed on your computer, to write and execute a Python program. It is also called Python shell.
  2. >>> : Symbol >>> is called Python prompt.
  3. Python prompt : Python prompt, which indicates that the interpreter is ready to receive instructions. We can type commands or statements on this prompt for execution.
Python Interpreter Shell

Chapter 3 Brief Overview of Python

Execution Mode / Working Mode in Python

There are two ways to run a program using the Python interpreter:
a) Interactive mode and b) Script mode

(A) Interactive Mode
In the interactive mode, we can type a Python statement on the >>> prompt directly. As soon as we press enter, the interpreter executes the statement and displays the result(s)

Executing code in Interactive mode

Advantages of using interactive mode : It is convenient for testing a single line code for instant execution.

Disadvantage of using Interactive mode : The interactive mode, we cannot save the statements for future use and we have to retype the statements to run them again.

(B) Script Mode
In the script mode, we can write a Python program in a file, save it and then use the interpreter to execute the program from the file.

  • Python program files have a .py extension.
  • Python programs are also known as scripts.
  • Python has a built-in editor called IDLE which can be used
    to create programs / scripts.

Python IDLE :

IDLE : Integrated Development and Learning Environment

To Create a Program

  • First open the IDLE,
  • Click File>New File to create a new file,
  • then write your program on that file and
  • save it with a desired name.
    By default, the Python scripts are saved in the Python installation folder.

To run / execute a program in script mode:

  • Open the program using an IDLE editor
  • In IDLE, go to [Run]->[Run Module] to execute the program
  • The output appears on shell.
Executing program in Script Mode

Chapter 3 Brief Overview of Python

Worksheet / Assignment – 1

  1. What do you mean by program and programming language?
  2. Give example of three programming language?
  3. What is language processor?
  4. Define – Compiler and Interpreter.
  5. What is Python?
  6. Who is the father of Python? / Who developed Python language?
  7. Python is developed by ________ and in year _______ .
  8. Write the name of three fields where Python can be used.
  9. Write the name of website to download the Python.
  10. What is Python Shell.
  11. What is >>> .
  12. In how many ways you can work in Python>
  13. What is Interactive Mode and Script Mode?
  14. In which condition you prefer (a) Interactive Mode , and (b) Script Mode.
  15. What is IDLE?
  16. Write down the steps for creating a script / program in Python.
  17. Write the steps to execute a Python script / program.

For Solution of Assignments (Visit here) :

To Download Notes in PDF(visit here) : https://www.anjeevsinghacademy.com/fundamentals-of-python-basic


Chapter – 3 : Brief overview of Python – Basics (Notes and Worksheets)


Token :

The smallest individual units of a program is called Token. Token is the basic building blocks of the python program.

Keywords:

Keywords are reserved words. Each keyword has a specific meaning to the Python interpreter. As Python
is case sensitive, keywords must be written exactly as defined in Python Interpreter.

Note : Maximum keywords are written in small letters, except False, True and None.

Keywords in Python

Identifiers

In programming languages, identifiers are names used to identify a variable, function, or other entities in a program.

The rules for naming an identifier in Python are as follows:

Do’s :

  • This may be followed by any combination of characters a-z, A-Z, 0-9 or underscore _ .
  • The name should begin with an uppercase or a lowercase alphabet or an underscore sign
  • It can be of any length. However, it is preferred to keep it short and meaningful.

Don’ts :

  • An identifier cannot start with a digit.
  • An identifier cannot contain space.
  • It should not be a keyword or reserved word.
  • We cannot use special symbols like !, @, #, $, %, etc. in identifiers.

For example, to find the average of marks obtained by a student in three subjects namely Maths, English, Informatics Practices (IP), we can choose the identifiers as marksMaths, marksEnglish, marksIP and avg rather than a, b, c, or A, B, C, as such alphabets do not give any clue about the data that variable refers to. avg = (marksMaths + marksEnglish + marksIP)/3

Chapter 3 Brief Overview of Python

Variables
Variable is an identifier whose value can change.

For example variable age can have different value for different person.

Variable Name:

Variable name is named memory location, use to refer the memory for processing of values. It should be unique in a program.

Value of a variable can be any data type like integer, float, string, Boolean, tuple, list, dictionary, none.

In Python, we can use an assignment statement (with = assignment operator) to create new variables and assign specific values to them.

Syntax : variableName = value

gender = ‘M’
message = “Keep Smiling”
price = 987.9

Variables must always be assigned values before they are used in the program, otherwise it will lead to an error-

NameError: name ‘variableName’ is not defined.

Wherever a variable name occurs in the program, the interpreter replaces it with the value of that particular variable.

Comments 

Comments are the additional information, readable by programmer but ignored by Python Interpreter. In Python, comments are written in three ways –

a) Full Line Comments – 

Using of # symbol in the beginning of line, i.e Physical line,

# This is a comment

# Helps in describing the purpose of program or function or module.

b) Inline Comment – 

It starts in the middle of line i.e. Physical line.

a1 = 20 # a1 is the marks of physics , <- Inline Comments

a2 = 30 # a2 is the marks of chemistry

c) Multi–line Comment- 

Python allows you to write the Multi-line comment or Block Comment. We can use # symbol in the beginning of each physical line, or we can write these multiline comment inside the triple quote (either double quote or single quote).

Example –   Method – 1

# Comment line 1

# Comment line2

# Comment line3

Method –

“”” Comment line 1

Comment line2 # This is also called docstring comment.

Comment line 3 “””


Click on the given link for the following –



Leave a Comment

You cannot copy content of this page

Scroll to Top