2010-07-23 13 views
9

पाइथन मुझे क्यों बता रहा है "टाइप एरर: पॉव 2 तर्क, 3 मिल गया" आईडीएलई में काम करने के बावजूद (कभी-कभी यह मुझे आईडीएलई में भी बताता है)? मैं बस pow(a,b,c) कर रहा हूँ। मेरा कार्यक्रम बहुत छोटा है और मैं किसी भी समय pow की परिभाषा को नहीं बदलता क्योंकि मुझे इसे कुछ एक्सपोनिएशन के लिए उपयोग करने की आवश्यकता है।पाइथन कहने वाले पाउ में केवल 2 तर्क क्यों हैं

नोट: यह __builtin__ से powMath

उत्तर

14

निर्मित pow में दो या तीन तर्क लेते हैं। यदि आप from math import * करते हैं तो इसे गणित के pow द्वारा प्रतिस्थापित किया जाता है, जिसमें केवल दो तर्क होते हैं। मेरी सिफारिश import math करना है, या आयात सूची में उपयोग किए जाने वाले कार्यों को स्पष्ट रूप से सूचीबद्ध करना है। इसी तरह की समस्या open बनाम os.open के साथ होती है।

+0

आह ... शायद यही कारण है कि। धन्यवाद!!!!! त्रुटि ... क्या किसी अन्य फ़ाइल से आयात प्रभावित करेगा? मैं एक और प्रोग्राम आयात कर रहा हूं जिसे मैंने लिखा है, जिसमें गणित आयात * ' – calccrypto

+0

@calccrypto भी है: यदि आप 'पी से आयात *' के साथ एक और प्रोग्राम आयात कर रहे हैं तो हाँ। 'आयात पी' का उपयोग करें या स्पष्ट रूप से 'आयात से आयात करें [...] '। – sdcvvc

0

http://docs.python.org/release/2.6.5/library/functions.html

pow(x, y[, z]) Return x to the power y; if z is present, return x to the power y, modulo z (computed more efficiently than pow(x, y) % z). The two-argument form pow(x, y) is equivalent to using the power operator: x**y.

The arguments must have numeric types. With mixed operand types, the coercion rules for binary arithmetic operators apply. For int and long int operands, the result has the same type as the operands (after coercion) unless the second argument is negative; in that case, all arguments are converted to float and a float result is delivered. For example, 102 returns 100, but 10-2 returns 0.01. (This last feature was added in Python 2.2. In Python 2.1 and before, if both arguments were of integer types and the second argument was negative, an exception was raised.) If the second argument is negative, the third argument must be omitted. If z is present, x and y must be of integer types, and y must be non-negative. (This restriction was added in Python 2.2. In Python 2.1 and before, floating 3-argument pow() returned platform-dependent results depending on floating-point rounding accidents.)

शायद आप बोल्ड भाग का उल्लंघन कर रहे है, है ना?

+0

नहीं के लिए __builtin__ आयात और __builtin__ .pow कॉल करने के लिए है। मुझे यकीन है कि सभी मान सकारात्मक पूर्णांक हैं संपादित करें: हाँ। ए, बी, सी = 9, 4, 225 – calccrypto

1

आप गणित कार्यों अजगर 2.7 में यह चारों ओर एक बहुत और पॉव के तीन पैरामीटर संस्करण बार बार एक तरह से उपयोग कर रहे हैं 3 paramete

+0

दोनों अंडरस्कोर वर्ण दोनों मामलों में 'builitin' के दोनों तरफ होना चाहिए लेकिन प्रारूपण ने व्याख्या की है कि बोल्ड फ़ॉन्ट के रूप में - सुनिश्चित नहीं है कि थैट के बारे में क्या करना है। –

संबंधित मुद्दे