python) implementing stack using python~!!

Hello~!
I'm lulu

Today I'm going to implement a stack using python.

Using python language to implement a stack, is a facile method.

Let's see how can we implement a stack using python.

class Stack:
    def __init__(self):
        self.items = []

    def is_empty(self):
        return not self.items
   
    def push(self, item):
        self.items.append(item)

    def pop(self):
        return self.items.pop()

    def peek(self):
        if self.items:
            return self.items[-1]
   
 

In this way, we can implement a stack using python easily :-)

If you have any questions or any opinions, tell me you'll be welcomed :-)
Thank you :-)

Comments

Popular posts from this blog

C언어) C언어를 이용하여 평균 구하기~!!

파이썬) 파이썬으로 사칙연산 계산기 만들기~!!

C언어) C언어를 이용하여 나의 BMI 측정하기(저체중, 표준체중, 과체중) 여러분도 직접 비만도를 측정해보세요~!!