Friday, January 8, 2010

Python is dynamically typed

Python is dynamically typed, the type of a object, or variable, is determined ar runtime. If you assign a int to g, g is int; then you re-assign a float to g, g is a float.

The Python build-in funtion type can be used to check the type of a object.

Try the following code:

g = 1
print(g, " g is ", type(g))
g =  5/2
print(g, " g is ", type(g))
g =  5//2
print(g, " g is ", type(g))
g = False
print(g, " g is ", type(g))
g = True * 1
print(g, " g is ", type(g))
g =  "Hello"
print(g, " g is ", type(g))
g =  ['hello', 'how', 'are', 'you']
print(g, " g is ", type(g))
g =  [1, 2, 3, 'you']
print(g, " g is ", type(g))
print(g[0], " g[0] is ", type(g[0]))
print(g[3], " g[3] is ", type(g[3]))
g = 3 + 2j
print(g, " g is ", type(g))



How to create a .py script in IDLE?

To create a .py script using IDLE

Start IDLE in Ubuntu, click Application -> Programming -> IDLE (using Python-3.1)

Click File -> New Window
A new window will be open, you can type your Python script here.



Then, you can save (File->Save or File->Save As) it as .py script file, or run it in Python Shell (Run->Run Moduel).


Thursday, January 7, 2010

Hello Python

To start your very first code, hello python:

Start IDLE:
Click Applications from Ubuntu top menu, then click Programming and IDLE (using python-3.1)

type the command below to say hello to Python, and RETUEN.

print ("hello")


Tuesday, January 5, 2010

Install Python 3.1 (the current version) on Ubuntu 9.10.

To install Python 3.1 (the current version) on Ubuntu 9.10.

Select Application -> Ubuntu Software Center from Ubuntu top menu.

Type Python3.1 inside the search box.



Select Python(3.1) and click the arrow on the right, and click Install to continuous. (You will be asked for password to continuoues)

Ubuntu Software Center will be downloaded and Installed automatically.


Then, you can go back to Ubuntu Software Center to install IDLE (using Python-3.1), a Integrated Development Environment for Python (v3.1), also if you want. It's suggested to do so.

After installed, you can close Ubuntu Software Center.

If you have a old version of Python installed on your Ubuntu, may be 2.6, both version of Python will be kept in your machine. So go to check the installed Python(s) now.

Start a Terminal, type 'python' will start your original python. To start the new installed Python 3.1, type 'python3.1'.


The IDLE will be installed under Application -> Programming -> IDLE (using Python-3.1).