Python Operator Overloading

Posted on Oct. 31, 2019, 1:31 p.m.

You have already seen you can use + operator for adding numbers and at the same time to concatenate strings. It is possible because + operator is overloaded by both int class and str class. The operators are actually methods defined in …

Read More

Python Object and Classes

Posted on Oct. 31, 2019, 12:37 p.m.

Creating object and classes #


Python is an object-oriented language. In python everything is object i.e int, str, bool even modules, functions are also objects.

Object oriented programming use objects to create programs, and these objects stores data and behaviours …

Read More

Python File Handling

Posted on Oct. 31, 2019, 12:36 p.m.

We can use File handling to read and write data to and from the file.

Opening a file #


Before reading/writing you first need to open the file. Syntax of opening a file is.

f = open(filename, mode)

The open …

Read More

Python Generating Random numbers

Posted on Oct. 30, 2019, 6:01 p.m.

Python random module contains function to generate random numbers. So first you need to import random module using the following line.

import random

random() Function #


The random() function returns random number r such that 0 <= r < 1.0 …

Read More

Python Mathematical Function

Posted on Oct. 30, 2019, 5:47 p.m.

Python has many inbuilt function.

Method Description
round(number[, ndigits])  rounds the number, you can also specify precision in the second argument
pow(a, b) Returns a raise to the power of b
abs(x) Return absolute value of x …
Read More

Python Loops

Posted on Oct. 30, 2019, 3:20 p.m.

Python has only two loops:

  1. for loop
  2. while loop

For loop #


The for loop Syntax:

1
2
for i in iterable_object:
   # do something

note:

All the statements inside for and while loop must be indented to the same number of …

Read More

Python Functions

Posted on Oct. 30, 2019, 2:46 p.m.

Functions are the re-usable pieces of code which helps us to organize structure of the code. We create functions so that we can run a set of statements multiple times during in the program without repeating ourselves.

Creating functions #


Python …

Read More

Python Control Statements

Posted on Oct. 30, 2019, 2:31 p.m.

It is very common for programs to execute statements based on some conditions. In this section we will learn about if else statement in Python.

But before we need to learn about relational operators. Relational operators allows us to compare …

Read More

Datatype Conversion

Posted on Oct. 30, 2019, 2:19 p.m.

Once in a while you will want to convert data type of one type to another type. Data type conversion is also known as Type casting.

Converting int to float #


To convert int to float you can use the float …

Read More

Python Tuples

Posted on Oct. 30, 2019, 2:15 p.m.

In Python Tuples are very similar to list but once a tuple is created, you cannot add, delete, replace, reorder elements.

note:

Tuples are immutable.

Creating a tuple #


1
2
3
4
5
6
7
>>> t1 = () # creates an empty …
Read More