Friday, January 30, 2015
Wednesday, January 28, 2015
Module
A module allows you to logically organize your Python code. Grouping
related code into a module makes the code easier to understand and use. A
module is a Python object with arbitrarily named attributes that you
can bind and reference.
One of the example of a module is tkinter module. The tkinter module is a tool for creating gui programs in python.
Source Code: example12.py |
Output: Python Shell - GUI |
Defining Function
A function is a block of organized, reusable code that is used to
perform a single, related action. Functions provide better modularity
for your application and a high degree of code reusing.
As you may have known, Python already provide you a wide variety of built-in function such as print() and input(). But you yourself can create/define a function to use in your programs. This is called user-defined-funtion.
Source Code: example11.py |
Output: Python Shell |
Python Dictionary
A dictionary is mutable and is another container type that can store any
number of Python objects, including other container types. Dictionaries
consist of pairs (called items) of keys and their corresponding values.
Source Code: example10.py |
Output: Python Shell |
Tuple
A tuple is a sequence of immutable Python objects. Tuples are sequences,
just like lists. The only difference is that tuples can't be changed
i.e., tuples are immutable and tuples use parentheses and lists use
square brackets.
Source Code: example9.py |
Output: Python Shell |
Python Lists
The list is a most versatile data type available in Python which can be
written as a list of comma-separated values (items) between square
brackets. Good thing about a list is that items in a list need not all
have the same type.
Source Code: example8.py |
Output: Python Shell |
While Loop
While loops, like the for loop, are used for repeating sections of code - but unlike a for loop, the while loop will not run n times, but until a defined condition is met.
Source Code: example7.py |
Output: Python Shell |
For Loop
For loops are traditionally used when you have a piece of code which you want to repeat n number of times.
Source Code: example6.py |
Output: Python Shell |
Subscribe to:
Posts (Atom)