Method overloading example in python

class Localbus: def sayLocal(self, busName=None): if busName is not None: print(‘Hello ‘ + busName) else: print(‘Hello ‘) obj = Localbus() obj.sayLocal() obj.sayLocal(‘Alif’) Output ============= Hello Hello Alif class Human: def sayHello(self, name=None, age=None): if name is not None and age is None: print(‘Hello ‘ + name) elif age is not None and age is not None: print(‘Hello ‘,name, ‘ your …

Continue Reading

Why Python for Data Analysis?

Python has become one of the most popular dynamic,programming languages, along with Perl, Ruby, and others. Python and Ruby havebecome especially popular in recent years for building websites using their numerous web frameworks, like Rails (Ruby) and Django (Python). Such languages are often called scripting languages as they can be used to write quick-and-dirty small programs,or scripts. I don’t like the term …

Continue Reading

Python String Operations

Concatenation >>>’Zend’ + ‘Anwar’ Zendanwar >>>’Zend’ *3 ZendZendZend Iterating Through String >> count = 0 >>> for str in ‘Zend Anwar’: if(str == ‘n’): count += 1 >>> print(count, “String Found”) 2 String Found  

Continue Reading

Syntax of Python Function

def functionname(parameters): “””docstring””” statement(s) return expression Example: #!/usr/bin/python # Function definition is here def ima( lovestr ): “This prints a passed string into this function” print lovestr return; # Now you can call ima function ima(“I’m fall in love!”)

Continue Reading

Star triangle with python for loop

>>> star =  input(“Enter the star to draw: “) Enter the star to draw: * >>> limit = int(input(“Enter the limit: “)) Enter the limit: 10 >>> for i in range(1, limit+1): print (star*i) Output–    * ** *** **** ***** ****** ******* ******** ********* **********

Continue Reading

How to show hostname & IP address with python programming

The Internet Protocol assigns a 4-byte address to every computer connected to the network. Such addresses are usually written as four decimal numbers, separated by periods, which each represent a single byte of the address. Each number can therefore range from 0 to 255. So an IP address looks like this: 202.168.3.180 Because purely numeric addresses can be difficult for …

Continue Reading