棧(stacks)是一種只能通過訪問其一端來實現資料儲存與檢索的線性資料結構,具有後進先出(last in first out,lifo)的特徵
class stack(object):
"""棧"""
def __init__(self):
self.__list=
def push(self,item):
"""入棧"""
def pop(self):
"""出棧"""
return self.__list.pop()
def peek(self):
"""返回棧頂元素"""
if self.__list:
return self.__list[-1]
else:
return none
def is_empty(self):
"""判斷棧是否為空"""
return self.__list==
def size(self):
"""返回棧的個數"""
return len(self.__list)
if __name__=="__main__":
s=stack()
s.push(1)
s.push(2)
s.push(3)
s.push(4)
print(s.pop())
print(s.size())
print(s.peek())
print(s.pop())
print(s.pop())
print(s.pop())
print(s.is_empty())
python 3 x 實現AES 加解密
首先 安裝cryptography sudo pip3 install cryptography確認安裝的是2.1.x版本 1.x版本的api是不一樣的 檔案頭部的宣告為 coding utf 8 import os from cryptography.hazmat.primitives.ciphe...
Python3 x編碼問題
1.記事本的ansi編碼為系統本地編碼,我的是gbk open 函式的encoding引數預設是本地編碼,也就是gbk,所以直接讀取ansi編碼的記事本檔案是木有問題的。怎麼檢視系統本地編碼?在cmd下輸入 chcp 從下表可以看出,936對應gbk編碼 下表列出了所有支援的 頁及其國家 地區 或者...
Python 內建函式(Python 3 x)
1 type obj 返回變數型別 2 isinstance object,class or type or tuple 測試物件是否為指定型別的例項 4 range start,end step 返回乙個 start,end 內的 range 物件,start 預設為 0,step 預設為 1 5...