Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Stack POP and PUSH operation using Python

# Hello World program in Python
    
print "Hello World!\n"


class Stack:

    def __init__(self):
        self.items=[]
    
    def isEmpty(self):
        self.items==[]
        
    def push(self,value):
        self.items.append(value)
        
    def pop(self):
        
        return self.items.pop()
    
    
    def peek(self):
        return self.items[len(self.items)-1]
        
    def size(self):
        return len(self.items)
        
    
    def __str__(self):
        return  str(self.items)

st=Stack()

st.push(5)
st.push(6)



print st.peek()

st.pop()

print st


st.pop()

print(st)

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.