99偷拍视频精品区一区二,口述久久久久久久久久久久,国产精品夫妇激情啪发布,成人永久免费网站在线观看,国产精品高清免费在线,青青草在线观看视频观看,久久久久久国产一区,天天婷婷久久18禁,日韩动漫av在线播放直播

Jython的操作符重載

本篇內容介紹了“Jython的操作符重載”的有關知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領大家學習一下如何處理這些情況吧!希望大家仔細閱讀,能夠學有所成!

匯川網站建設公司創新互聯,匯川網站設計制作,有大型網站制作公司豐富經驗。已為匯川近1000家提供企業網站建設服務。企業網站搭建\成都外貿網站建設要多少錢,請找那個售后服務好的匯川做網站的公司定做!

Jython的操作符重載

像 C++ 一樣,但是與 Java 語言不同,Jython 允許類重載許多標準語言操作符。這意味著類可以為語言操作符定義特定的意義。 Jython 還允許類模仿內置類型,如數字、序列和映射。

在下面的例子中,我們將使用標準 Jython UserList 類定義展示實際的操作符重載的例子.UserList 是一個包裝了一個列表的類,它的行為也像列表。它的大多數函數都 指派(傳遞)給其包含的列表,稱為data。在一個更實際的Jython操作符重載的例子中,會實現這些重載的函數以訪問其他一些存儲,如磁盤文件或者數據庫。

class UserList:      def __init__(self, initlist=None):          self.data = []          if initlist is not None:              if   type(initlist) == type(self.data):                  self.data[:] = initlist              elif isinstance(initlist, UserList):                  self.data[:] = initlist.data[:]              else:                  self.data = list(initlist)       def __cast(self, other):          if isinstance(other, UserList): return other.data          else:                           return other       #  `self`, repr(self)      def __repr__(self): return repr(self.data)       #  self < other      def __lt__(self, other): return self.data <  self.__cast(other)       #  self <= other      def __le__(self, other): return self.data <= self.__cast(other)       #  self == other      def __eq__(self, other): return self.data == self.__cast(other)       #  self != other, self <> other      def __ne__(self, other): return self.data != self.__cast(other)       #  self > other      def __gt__(self, other): return self.data >  self.__cast(other)       #  self >= other      def __ge__(self, other): return self.data >= self.__cast(other)       #  cmp(self, other)      def __cmp__(self, other):          raise RuntimeError, "UserList.__cmp__() is obsolete"      #  item in self      def __contains__(self, item): return item in self.data       #  len(self)      def __len__(self): return len(self.data)       #  self[i]      def __getitem__(self, i): return self.data[i]       #  self[i] = item      def __setitem__(self, i, item): self.data[i] = item       #  del self[i]      def __delitem__(self, i): del self.data[i]       #  self[i:j]      def __getslice__(self, i, j):          i = max(i, 0); j = max(j, 0)          return self.__class__(self.data[i:j])       #  self[i:j] = other      def __setslice__(self, i, j, other):          i = max(i, 0); j = max(j, 0)          if   isinstance(other, UserList):              self.data[i:j] = other.data          elif isinstance(other, type(self.data)):              self.data[i:j] = other          else:              self.data[i:j] = list(other)       #  del self[i:j]      def __delslice__(self, i, j):          i = max(i, 0); j = max(j, 0)          del self.data[i:j]       #  self + other   (join)      def __add__(self, other):          if   isinstance(other, UserList):              return self.__class__(self.data + other.data)          elif isinstance(other, type(self.data)):              return self.__class__(self.data + other)          else:              return self.__class__(self.data + list(other))       #  other + self   (join)      def __radd__(self, other):          if   isinstance(other, UserList):              return self.__class__(other.data + self.data)          elif isinstance(other, type(self.data)):              return self.__class__(other + self.data)          else:              return self.__class__(list(other) + self.data)       #  self += other  (join)      def __iadd__(self, other):          if   isinstance(other, UserList):              self.data += other.data          elif isinstance(other, type(self.data)):              self.data += other          else:              self.data += list(other)          return self      #  self * other   (repeat)      def __mul__(self, n):          return self.__class__(self.data*n)      __rmul__ = __mul__       #  self *= other  (repeat)      def __imul__(self, n):          self.data *= n          return self      # implement "List" functions below:       def append(self, item): self.data.append(item)       def insert(self, i, item): self.data.insert(i, item)       def pop(self, i=-1): return self.data.pop(i)       def remove(self, item): self.data.remove(item)       def count(self, item): return self.data.count(item)       def index(self, item): return self.data.index(item)       def reverse(self): self.data.reverse()       def sort(self, *args): apply(self.data.sort, args)       def extend(self, other):          if isinstance(other, UserList):              self.data.extend(other.data)          else:              self.data.extend(other)

“Jython的操作符重載”的內容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業相關的知識可以關注創新互聯網站,小編將為大家輸出更多高質量的實用文章!

名稱欄目:Jython的操作符重載
當前地址:http://www.yijiale78.com/article0/ihdgio.html

成都網站建設公司_創新互聯,為您提供Google自適應網站移動網站建設品牌網站設計網站導航品牌網站制作

廣告

聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯

成都網站建設