Chapter_1 Review of Phython

Learning Objectives:

At the end of this chapter the students will be able to understand:

  • Interactive Mode
  • Script Mode
  • Data Types
  • Functions in Python
  • Sequential Statement
  • Selective Statements
  • Looping Statements
  • String and String Methods
  • List and List Methods
  • Tuple and Tuple Methods
  • Dictionary and Dictionary Methods

Interactive Mode

Here, when we type Python statement, interpreter displays the result(s) immediately. That means, when we type Python expression / statement / command after the prompt (>>>), the Python immediately responses with the output of it:

Python 3.x.y
[GCC 4.x] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>3+4
7

Script Mode

In script mode, we type Python program in a file and then use interpreter to execute the content of the file. Working in interactive mode is convenient for beginners and for testing small pieces of code, as one can test them immediately. But for coding of more than few lines, we should always save our code so that it can be modified and reused.

sum.py
num1 = int(input("Enter first Number :"))
num2 = int(input("Enter Second Number: "))
sum = num1+num2
print("Sum of two number is :", sum)
OUTPUT :
Enter first Number : 5
Enter Second Number : 8
Sum of two number is : 13

Note

Python, in interactive mode, is good enough to learn, experiment or explore, but its only drawback is that we cannot save the statements and have to retype all the statements once again to re-run them.