Monthly Archives: January 2016

Write file

Writing files is easy: Python has built in support for writing files. In this article we’ll show you how to write data to a file. To write a file, we must first open it. We can open the file with method open(filename, flag). The flag needs to be ‘w’, short for write. Related Courses Example […]

Date and Time

Introduction Computers handle time using ticks. To get the date or time in Python we need to use the standard time module. Note: All computers keep track of time since 12:00am, January 1, 1970, known as epoch time.   Related Course: Epoch time To get the number of ticks, use this program:

The output […]

Comments

Comments are little texts that can be added in code. They are created for programmers to read, not computers.  A comment is simply one or more lines of text that is not executed by the computer. There are two ways to comment in Python: single-line comments and multi-line comments.   Related Courses Single line comment […]

How to install modules

Python modules allow you to use code of others in your code. This saves you a lot of development time, you don’t have to reinvent the wheel each time. There are two ways to install Python modules: system wide and using a virtual environment. You may like: Virtualenv We can create a virtual environemnt, that […]

Modules

What is a module? why? A module is a Python file with one or more functions and variables.  These functions and variables can be called from your program by importing a module. Modules can be used to organize your code.  You may like In this example we use the math module. This module has many […]

Random Numbers

The random module can be used to make random numbers in Python. The function random() generates a number between 0 and 1. Online Courses Generate random nubers Generate a real number between 0 and 1 Simply call the random() method to generate a real (float) number between 0 and 1.

Generate a number between […]