Category Archives: Python Tutorial
An exception is an error or event that occurs during a program execution. Depending on error type, exception may crash a program or result in some unexpected behaviour. In order to avoid crashing or end program in unwanted way error must be handled immediately.
In Python Set is almost similar to dictionary. A set is dictionary with no values. As described in dictionary chapter, dictionary data type work with key – value pairs as shown below:
Python variables and data-types Variables are way to store values that are changeable. Variable has data types that defines what kind of data to store in that variable. For example numbers, strings etc. Python has following standard data types: Numbers (int, float etc.) String Dictionary Tuple List Python Numeric data types Python has three
The open method of Python Python comes up with a built-in function open() that enables programmers to perform open, read, write and other operations with files. >>An example of Open and read file In order to perform the read or write actions in the files, first, it has to be opened. Once a file is opened by
Grouping similar types of tasks into classes is termed as object oriented programming. Where Class is a combination of variables/properties and functions/methods. This chapter does not aim at explaining object oriented programming concepts thoroughly. The aim of this chapter is how to create and use Python classes.
A python function is a block of code that may take one or more input parameters, executes and may return a value. Functions can be used in Python programs repeatedly. A function’s code will only be executed once this is called.
Python has a function called range() that is used to create list of integers. For example range(5) is the length of 5 numbers. By default Python range starts from 0.
Among other compound data types available in Pytho,n tuple is one of those. The Tuple is sequence just like list but this type is immutable. That means its values cannot be changed. Once created, rest of the program it will stay same. Besides list use square brackets while tuples use parentheses ().
Python comes up with a few date and time modules. One of those is python datetime. In order to format date and time you have to import datetime module into your Python programs. This chapter explains how to format date and time with datetime python module, let us first show you how to import datetime in Python program.
Taking user input from keyboard is sometimes required in programming languages. For example developing a calculator, a menu system etc. that asks users to input some value. Python comes up with input() method that allows programmers to take user input.