2. UNIT 1 : SYLLABUS
• Conceptual introduction: topics in computer science, algorithms;
• Modern computer systems: hardware architecture, data
representation in computers, software and operating system;
• Installing Python; basic syntax, interactive shell, editing, saving, and
running a script.
• The concept of data types; variables, assignments; immutable
variables; numerical types;
• arithmetic operators and expressions; comments in the program;
understanding error messages;
3. Guido Van Rossum published the
first version of Python code
(Python 0.9.0) in February 1991.
This release included exception
handling, functions and the core
data types.
Python 1.0 released in
January 1994. It included
filters, map, reduce and
lambda
Python 2.0 released in October
2000. Features include list
comprehension and garbage
collection with reference cycles
4. Python 3.0 released in December
2008. Removed duplicate
constructs and modules. Not
backward compatible.
5. 1
2
3
4
5
6
FREE AND OPEN SOURCE
The standard modules and
the Python interpreter are
free.
PORTABLE
Python interpreter exists for
almost all platforms/operating
systems.
SIMPLE & EASY TO LEARN
Python has a very simple
syntax; it means it is very
easy to learn and code.
EXTENSIVE
LIBRARIES
The Python Standard
Library is very exhaustive
library
EXTENSIBLE
&EMBEDDABLE
One can embed Python
within a C or C++
program.
OBJECT ORIENTED
Python supports object-
oriented programming
Features of
Python
17. Basic syntax & Interactive shell
The instructions written
in Python programming language can be
executed in two modes:
• Interactive mode
• Normal or Script mode
Interactive mode:
In this mode, lines of code is directly written and
executed in the Python interpreter shell, which
instantaneously provide the results.
Normal or Script mode:
In this mode the source code is saved to a file
with .py extension, and the file is executed
by the Python interpreter.
A shell window contains an opening message
followed by the special symbol >>>, called a shell
prompt.
20. Basic syntax & Interactive shell
The programmer can also display the output
of a value by using the print function.
print(<expression>)
To begin the next output on the same line as the
previous one, you can place the expression end = “
”
>>> print("Python" , end = ' ')
>>> print(“Programming")
write a print function that includes two or
more expressions separated by commas.
In such a case, the print function evaluates
the expressions and displays the results,
separated by single spaces, on one line.
print(<expression>,..., <expression>)
>>> print ("Hi there")
Hi there
>>> print(3+4,8-5,"hello")
7 3 hello
21. Basic syntax & Interactive shell
Programs to ask the user for input. You can
do this by using the input function.
>>> name = input("Enter your name: ")
Enter your name: RISE Group
>>> name
' RISE Group '
>>> print(name)
Ken Lambert
The input function does the following:
1. Displays a prompt for the input. In this
example, the prompt is "Enter your name: ".
2. Receives a string of keystrokes, called
characters, entered at the keyboard and
returns the string to the shell.
This function causes the program to stop and
wait for the user to enter a value from the
keyboard.
22. Basic syntax & Interactive shell
• The input function always builds a string
from the user’s keystrokes and returns it
to the program.
• After inputting strings that represent
numbers, the programmer must convert
them from strings to the appropriate
numeric types.
• In Python, there are two type conversion
functions for this purpose, called int (for
integers) and float (for floating point
numbers).
>>> first = int(input("Enter the first number:
"))
Enter the first number: 23
>>> second = int(input("Enter the second
number: "))
Enter the second number: 44
>>> print("The sum is", first + second)
The sum is 67
24. Editing, Saving, and Running a script.
• It is more convenient to
compose, edit, and save longer,
more complex programs in
files.
• We can then run these program
files or scripts either within
IDLE or from the operating
system’s command prompt
without opening IDLE.
Perform the following steps:
1. Select the option New Window from the File
menu of the shell window.
2. In the new window, enter Python expressions or
statements on separate lines, in the order in which
you want Python to execute them.
3. At any point, you may save the file by selecting
File/Save. If you do this, you should use a . py
extension. For example, your first program file
might be named myprogram.py.
4. To run this file of code as a Python script, select
Run Module from the Run menu or press the F5 key.
26. UNIT 1 : SYLLABUS
• Conceptual introduction: topics in computer science, algorithms;
• Modern computer systems: hardware architecture, data
representation in computers, software and operating system;
• Installing Python; basic syntax, interactive shell, editing, saving, and
running a script.
• The concept of data types; variables, assignments; immutable
variables; numerical types;
• arithmetic operators and expressions; comments in the program;
understanding error messages;