Monday, March 19, 2012

csci133Buildin.py

Everything in Python are objects, and python's build-in types are objects too. When you use the build-in types, you don't have to worry about anything such as memory allocation, implement insert, search, sort, list, print, and get routines. We can start immediately work on our code. *In C++, we usually call them functions, In JAVA, we call them methods and finally, in Python, they are called routines. Here is a list of reason why you should try to use build-in types as much as you can.
  1. They are easy- if you need simple program, they are great for fast development , easy to write, debug, and for others to read and understand your code. You can write a program to calculate expense in just about 5 mins using the build in types.
  2. They are useful - you can use them to build more complex object. They are like lego, you can stack them and form different tools.
  3. Efficient - if you want performance, look no further, they are perfected by developer, and will only get better as more release follow. It is less likely you will write a more efficient routines than them, although maybe for highly specialized input.
  4. Always here - every python comes with them, you don't have to download anything extra, and they are standardize cross everyone. Everyone has the same copies when they download the Python.

Name
Example
Sample Code
Reference
Number
12345, 1234.5
String
‘Hello Python’
List
[1, 2, 3] [‘a’, ‘b’, ‘c’]
csci133list.py
Dictionary
{‘username’:’password’}
csci133dictionary.py
Boolean
True, False
csci133boolean.py

Here is an index of some of the basic build in types offered by python, please note there are a lot more other kinds that I didn't have a chance to cover! Although it is my goal, to write about all the build in data types :) . Python is dynamically typed (instead of declaring the type and compile the code), and strongly typed (means you can not perform other type function on another type). It is something to keep in mind when you are learning other languages.

No comments:

Post a Comment