Pages

Saturday, May 19, 2012

How to clear Python shell


Unfortunately, I don't think there is a way to clear the screen in IDLE. The best you could do is to scroll the screen down lots of lines, eg:
print "\n" * 100
Though you could put this in a function:
def cls(): print "\n" * 100
And then call it when needed as cls().

However, if you are using the command line, you can use the following to clear the command line.
import os
os.system("cls")

Thursday, May 17, 2012

Type System in Programming Languages

Static Typing:
A programming language is said to be statistically typed if
1. The variable type is known at compile time by data declaration. This means that we as a programmer  must specify what type each variable is. Eg: C,C++, Java
2. The variable name is bound to an object.(optionl). If not it(the name) is said to be null

The advantage is that all kinds of checking can be done at compile time and a lot of stupid bugs can be caught at an early stage.However, it cannot be bound to an object of different type. Any attempt to bind the name to an object of the wrong type will raise an exception.

Dynamic Typing:
A programming language is said to be dynamically typed if
1. A variable name(unless it is null) is bound to only to an object. Names are bound to objects at execution time by means of assignment statements and it is possible to bind a name to objects of different types during the execution of the program. Eg: Python

Weak Typing:

In weak typing, variables can be implicitly coerced to unrelated types.Eg:

a  = 9
b = "9"
c = concatenate(a, b)  // produces "99" 
d = add(a, b) // produces 18

Strong Typing:

To coerce unrelated types, an explicit conversion is needed.

a  = 9
b = "9"
c = concatenate(  str(a),  b) 
d = add(a, int(b) )


Tuesday, April 17, 2012