Swap Program in Python

Python
Python


Code:


class abc:
    def __init__(self):
        self.n=20
        self.m=50
    def swap(self):
        temp=self.n
        self.n=self.m
        self.m=temp
    def output(self):
        print("n = ",self.n , "m = ",self.m)
a=abc()

Output:

>>> a.m
50
>>> a.n
20
>>> a.swap()
>>> a.output()
n =  50 m =  20
>>> 

Tags: python,python programming,swap,how to swap values in python,python tutorial,python program to swap two numbers,swapping in python,tuple swap python,swap() python,swap two numbers,write a program to swap two numbers in python3,swap python function,python program to swap two numbers using third variable,swapping of two numbers in python,python swap,swap two values in python,swap values in python

Post a Comment

Previous Post Next Post