3.0 Programming style in python
Python is defined as an interpreted, high-level programming language, pure object-oriented, and power server-side scripting language for the Web. Python supports more than one style and this feature is what makes it great. Python has no compilation or linking process (Lessa, A, 2001). But, it supports byte compilation. The compiled code is saved in bytecode that can be accessed by any PVM -Python Virtual Machine- so applications can be used in any system without the need for compilation.
Everything in Python is an object, and almost everything has attributes and methods. All functions have a built-in attribute __doc__, which returns the doc string defined in the function's source code. The sys module is an object which has (among other things) an attribute called path. And so forth (Pilgrim. M, 2004).
What is an object in python? Since object has differ in terms of definition from a programming language to another. In python, some objects have neither attributes nor methods(Pilgrim. M, 2004), and not all objects are can be subclasses. But, everything is an object in the sense that it can be assigned to a variable or passed as an argument to a function (Pilgrim. M, 2004). For example:
>> class Student:
default_age=20 # class variable
def__init__(self,age):
self.default_age = age #instance variable
Scripting in python is another interesting side, whereby user code doesn't have to be recompiled. The python virtual machine interprets the bytecode in any system that has python interpreter. Python also supports imperative style in it's coding. For example:
def trythis:
print x
x =1
The code above will generate an error. Because x is declared after the print and that is not how the it goes in declarative/imperative languages. To fix the code above we have to write it this way:
def trythis:
x=1
print x
Python is defined as an interpreted, high-level programming language, pure object-oriented, and power server-side scripting language for the Web. Python supports more than one style and this feature is what makes it great. Python has no compilation or linking process (Lessa, A, 2001). But, it supports byte compilation. The compiled code is saved in bytecode that can be accessed by any PVM -Python Virtual Machine- so applications can be used in any system without the need for compilation.
Everything in Python is an object, and almost everything has attributes and methods. All functions have a built-in attribute __doc__, which returns the doc string defined in the function's source code. The sys module is an object which has (among other things) an attribute called path. And so forth (Pilgrim. M, 2004).
What is an object in python? Since object has differ in terms of definition from a programming language to another. In python, some objects have neither attributes nor methods(Pilgrim. M, 2004), and not all objects are can be subclasses. But, everything is an object in the sense that it can be assigned to a variable or passed as an argument to a function (Pilgrim. M, 2004). For example:
>> class Student:
default_age=20 # class variable
def__init__(self,age):
self.default_age = age #instance variable
Scripting in python is another interesting side, whereby user code doesn't have to be recompiled. The python virtual machine interprets the bytecode in any system that has python interpreter. Python also supports imperative style in it's coding. For example:
def trythis:
print x
x =1
The code above will generate an error. Because x is declared after the print and that is not how the it goes in declarative/imperative languages. To fix the code above we have to write it this way:
def trythis:
x=1
print x