[轉載] python類運算符的重載

參考鏈接: Python中的運算符重載

alist = input().split()

?

blist = input().split()

?

n = float(input())

?

?

class Vector:

? ? def __init__(self, x=0, y=0, z=0):

? ? ? ? # 請在此編寫你的代碼(可刪除pass語句)

? ? ? ? self.X = x

? ? ? ? self.Y = y

? ? ? ? self.Z = z

?

? ? ? ? # 代碼結束

?

? ? def __add__(self, other):

?

? ? ? ? return Vector(self.X + other.X, self.Y + other.Y, self.Z + other.Z)

?

?

? ? ? ? # 代碼結束

?

? ? def __sub__(self, other):

?

? ? ? ? return Vector(self.X - other.X, self.Y - other.Y, self.Z -other.Z)

?

?

?

?

? ? ? ? # 代碼結束

?

? ? def __mul__(self, other):

?

? ? ? ? return Vector(self.X * other, self.Y * other, self.Z * other)

? ? ? ? # 請在此編寫你的代碼(可刪除pass語句)

?

?

?

? ? ? ? # 代碼結束

?

? ? def __truediv__(self, other):

?

? ? ? ? return Vector(self.X / other, self.Y / other, self.Z / other)

? ? ? ? # 請在此編寫你的代碼(可刪除pass語句)

?

?

?

?

?

? ? ? ? # 代碼結束

?

? ? def __str__(self):

? ? ? ? # 請在此編寫你的代碼(可刪除pass語句)

? ? ? ? return '(%.1f,%.1f,%.1f)' % (self.X, self.Y, self.Z)

?

?

?

?

?

?

?

?

a = Vector(float(alist[0]), float(alist[1]), float(alist[2]))

?

b = Vector(float(blist[0]), float(blist[1]), float(blist[2]))

?

print(a + b, a - b, a * n, a / n)

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/540530.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/540530.shtml
英文地址,請注明出處:http://en.pswp.cn/news/540530.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

r語言 運算符_R語言運算符

r語言 運算符R語言中的運算符 (Operators in R Language) Generally speaking, an operator is a symbol that gives proper commands to the compiler regarding a specific action to be executed. The operators are used for carrying out the mathematical or logical cal…

[轉載] Python基礎之類型轉換與算術運算符

參考鏈接: Python中的運算符函數| 1 一、注釋 1.注釋:對程序進行標注和說明,增加程序的可讀性。程序運行的時候會自動忽略注釋。 2.單行注釋:使用#的形式。但是#的形式只能注釋一行,如果有多行,就不方便…

java awt 按鈕響應_Java AWT按鈕

java awt 按鈕響應The Button class is used to implement a GUI push button. It has a label and generates an event, whenever it is clicked. As mentioned in previous sections, it extends the Component class and implements the Accessible interface. Button類用于…

解決“由于應用程序的配置不正確,應用程序未能啟動,重新安裝應用程序可能會糾正這個問題”...

在VS2005下用C寫的程序,在一臺未安裝VS2005的系統上, 用命令行方式運行,提示: “系統無法執行指定的程序” 直接雙擊運行,提示: “由于應用程序的配置不正確,應用程序未能啟動,重新安…

qgis在地圖上畫導航線_在Laravel中的航線

qgis在地圖上畫導航線For further process we need to know something about it, 為了進一步處理,我們需要了解一些有關它的信息, The route is a core part in Laravel because it maps the controller for sending a request which is automatically …

Logistic回歸和SVM的異同

這個問題在最近面試的時候被問了幾次,讓談一下Logistic回歸(以下簡稱LR)和SVM的異同。由于之前沒有對比分析過,而且不知道從哪個角度去分析,一時語塞,只能不知為不知。 現在對這二者做一個對比分析&#xf…

[轉載] python學習筆記2--操作符,數據類型和內置功能

參考鏈接: Python中的Inplace運算符| 1(iadd(),isub(),iconcat()…) 什么是操作符? 簡單的回答可以使用表達式4 5等于9,在這里4和5被稱為操作數,被稱為操符。 Python語言支持操作者有以下幾種類型。 算…

scala bitset_Scala中的BitSet

scala bitsetScala BitSet (Scala BitSet) Set is a collection of unique elements. 集合是唯一元素的集合。 Bitset is a set of positive integers represented as a 64-bit word. 位集是一組表示為64位字的正整數。 Syntax: 句法: var bitset : Bitset Bits…

構建安全網絡 比格云全系云產品30天內5折購

一年之計在于春,每年的三、四月,都是個人創業最佳的起步階段,也是企業采購最火熱的時期。為了降低用戶的上云成本,讓大家能無門檻享受到優質高性能的云服務,比格云從3月16日起,將上線“充值30天內&#xff…

python中 numpy_Python中的Numpy

python中 numpyPython中的Numpy是什么? (What is Numpy in Python?) Numpy is an array processing package which provides high-performance multidimensional array object and utilities to work with arrays. It is a basic package for scientific computati…

[轉載] python之路《第二篇》Python基本數據類型

參考鏈接: Python中的Inplace運算符| 1(iadd(),isub(),iconcat()…) 運算符 1、算數運算: 2、比較運算: 3、賦值運算: 4、邏輯運算: 5、成員運算: 6、三元運算 三元運算&…

數據結構 基礎知識

一。邏輯結構: 是指數據對象中數據 素之間的相互關系。 其實這也是我 今后最需要關注的問題 邏輯結構分為以 四種1. 集合結構 2.線性結構 3.數形結構 4,圖形結構 二。物理結構: 1,順序存儲結,2 2. 鏈式存儲結構 一,時間復雜…

ruby 變量類中范圍_Ruby中的類

ruby 變量類中范圍Ruby類 (Ruby Classes) In the actual world, we have many objects which belong to the same category. For instance, I am working on my laptop and this laptop is one of those laptops which exist around the globe. So, this laptop is an object o…

以云計算的名義 駐云科技牽手阿里云

本文講的是以云計算的名義 駐云科技牽手阿里云一次三個公司的牽手 可能會改變無數企業的命運 2017年4月17日,對于很多人來說可能只是個平常的工作日,但是對于國內無數的企業來說卻可能是個會改變企業命運的日。駐云科技聯合國內云服務提供商阿里云及國外…

[轉載] python學習筆記

參考鏈接: Python | a b并不總是a a b 官網http://www.python.org/ 官網library http://docs.python.org/library/ PyPI https://pypi.python.org/pypi 中文手冊,適合快速入門 http://download.csdn.net/detail/xiarendeniao/4236870 py…

標志寄存器_訪問標志寄存器,并與寄存器B |交換標志寄存器F的內容 8085微處理器...

標志寄存器Problem statement: 問題陳述: Write an assembly language program in 8085 microprocessor to access Flag register and exchange the content of flag register F with register B. 在8085微處理器中編寫匯編語言程序以訪問標志寄存器,并…

瀏覽器端已支持 ES6 規范(包括 export import)

當然,是幾個比較優秀的瀏覽器,既然是優秀的瀏覽器,大家肯定知道是那幾款啦,我就不列舉了,我用的是 chrome。 對 script 聲明 type 為 module 后就可以享受 es6 規范所帶來的模塊快感了。 基礎語法既然是全支持&#xf…

[轉載] Python學習:Python成員運算符和身份運算符

參考鏈接: Python中和is運算符之間的區別 Python成員運算符 除了以上的一些運算符之外,Python還支持成員運算符,測試實例中包含了一系列的成員,包括字符串,列表或元組。 運算符 描述 實例 in 如果在指定的序列中找…

量詞邏輯量詞里面的v表示?_代理知識表示中的量詞簡介(基于人工智能)

量詞邏輯量詞里面的v表示?As we know that in an AI-based agent, the knowledge is represented through two types of logic: The propositional logic and the predicate logic. In the propositional logic, we have declarative sentences, and in the predica…

[轉載] Python 機器學習經典實例

參考鏈接: Python中的邏輯門 內容介紹 在如今這個處處以數據驅動的世界中,機器學習正變得越來越大眾化。它已經被廣泛地應用于不同領域,如搜索引擎、機器人、無人駕駛汽車等。本書首先通過實用的案例介紹機器學習的基礎知識,然后…