Posts

Showing posts from September, 2018

Variables and Types

Image
Variables and Types When we create a program, we often like to store values so that it can be used later. We use objects to capture data, which then can be manipulated by computer to provide information. By now we know that object/ variable is a name which refers to a value. Every object has: An Identity -             can be known using id (object) A type –                     can be checked using type (object) and A value –                   any value Identity of the object: It is the object's address in memory and does not change once it has been created. Type (i.e data type): It is a set of values, and the allowable operations on those values. It can be one of the following: 1. Number Number data type stores...

Script Mode

Image
In script mode, we type Python program in a file and then use the interpreter to execute the content from the file. To create and run a Python script, we will use following steps in IDLE, if the script mode is not made available by default with IDLE environment. 1. File>Open OR File>New Window (for creating a new script file) 2. Write the Python code as function i.e. script 3. Save it (^S) 4. Execute it in interactive mode- by using RUN option (^F5) If we write Example 1 in script mode, it will be written in the following way: Firstly:            File> New Window Secondly:      Define a function def test(): x=2 y=6 z = x+y print z Thirdly:   Use File > Save or File > Save As - option for saving the file (By convention all Python program files have names which end with .py) Fourthly: For execution, press ^F5, and we will go to Python promp...

Interactive Mode of Python 2.7

Image
Interactive Mode of Python 2.7 What we see is a welcome message of Python interpreter with revision details and the Python prompt, i.e., „>>> ‟ . This is a primary prompt indicating that the interpreter is expecting a python command. There is secondary prompt also which is „… ‟ indicating that interpreter is waiting for additional input to complete the current statement. Interpreter uses prompt to indicate that it is ready for instruction. Therefore, we can say, if there is prompt on screen, it means IDLE is working in interactive mode. We type Python expression / statement / command after the prompt and Python immediately responds with the output of it. Let ‟ s start with typing print “How are you” after the prompt. >>>print “How are you?” How are you? What we get is Python ‟ s response. We may try the following and check the response: i) print 5+7 ii) 5+7 iii) 6*250/9 iv) print 5-7 It is also possible to get a sequence of in...

Python Introduction

Python was created by Guido Van Rossum when he was working at CWI (Centrum Wiskunde & Informatica) which is a National Research Institute for Mathematics and Computer Science in Netherlands. The language was released in I991. Python got its name from a BBC comedy series from seventies- “Monty Python‟s Flying Circus”. Python can be used to follow both Procedural approach and Object Oriented approach of programming. It is free to use. Some of the features which make Python so popular are as follows: 1. It is a general purpose programming language which can be used for both scientific and non scientific programming. 2. It is a platform independent programming language. 3. It is a very simple high level language with vast library of add-on modules. 4. It is excellent for beginners as the language is interpreted, hence gives immediate results. 5. The programs written in Python are easily readable and understandable. 6. It is suitable as an extension language for customizable...