ÎÊÌâÃèÊö
Ϊʲôpython¸æËßÎÒ¡°TypeError£ºpowÔ¤ÆÚ2¸ö²ÎÊý£¬µÃµ½3¡±¾¡¹ÜËüÔÚIDLEÖй¤×÷£¨ÓÐʱËü¸æËßÎÒÔÚIDLEÖÐÒ²ÊÇÈç´Ë£©£¿
ÎÒÖ»ÊÇ×öpow(a,b,c)
¡£
ÎҵijÌÐòºÜ¶Ì£¬ÎÒ²»»áËæʱ¸ü¸Äpow
µÄ¶¨Ò壬ÒòΪÎÒÐèҪʹÓÃËüÀ´½øÐÐһЩȡÃÝ¡£
×¢Ò⣺ÕâÊÇÀ´×Ô__builtin__
µÄpow
£¬¶ø²»ÊÇMath
1Â¥
ÄÚÖÃpow
ÐèÒªÁ½¸ö»òÈý¸ö²ÎÊý¡£
Èç¹ûÄãfrom math import *
ÄÇÀïÈ¡¶ø´úÖ®µÄÊÇmathµÄpow
£¬ËüÖ»ÐèÒªÁ½¸ö²ÎÊý¡£
ÎҵĽ¨ÒéÊǽøÐÐimport math
£¬»òÃ÷È·ÁгöÄúÔÚµ¼ÈëÁбíÖÐʹÓõĺ¯Êý¡£
open
ºÍos.open
·¢ÉúÀàËƵÄÎÊÌâ¡£
2Â¥
Èç¹ûÄãÕýÔÚʹÓÃÊýѧº¯ÊýºÜ¶à¶øÇÒÔÚpython 2.7ÖкÜÉÙʹÓÃpowµÄÈý¸ö²ÎÊý°æ±¾¾ÍÊǵ¼Èë__builtin__
²¢Îª3²ÎÊýµ÷ÓÃ__builtin__
.pow
3Â¥
pow(x, y[, z])
x·µ»Øµ½ÃÝy; Èç¹ûz´æÔÚ£¬Ôò½«x·µ»Øµ½ÃÝy£¬Ä£z£¨±Èpow£¨x£¬y£©£¥z¸üÓÐЧµØ¼ÆË㣩¡£ Á½¸ö²ÎÊýÐÎʽpow£¨x£¬y£©Ï൱ÓÚʹÓÃÃÝÔËËã·û£ºx ** y¡£²ÎÊý±ØÐë¾ßÓÐÊý×ÖÀàÐÍ¡£ ¶ÔÓÚ»ìºÏ²Ù×÷ÊýÀàÐÍ£¬¶þ½øÖÆËãÊõÔËËã·ûµÄÇ¿ÖƹæÔòÊÊÓᣠ¶ÔÓÚintºÍlong int²Ù×÷Êý£¬½á¹ûÓë²Ù×÷Êý¾ßÓÐÏàͬµÄÀàÐÍ£¨ÔÚÇ¿ÖÆÖ®ºó£©£¬³ý·ÇµÚ¶þ¸ö²ÎÊýÊÇ·ñ¶¨µÄ; ÔÚÕâÖÖÇé¿öÏ£¬ËùÓвÎÊý¶¼×ª»»Îªfloat²¢´«µÝfloat½á¹û¡£ ÀýÈ磬10 2·µ»Ø100£¬µ«10 -2·µ»Ø0.01¡£ £¨×îºóÒ»¸öÌØÐÔÊÇÔÚPython 2.2ÖÐÌí¼ÓµÄ¡£ÔÚPython 2.1ºÍ֮ǰ£¬Èç¹ûÁ½¸ö²ÎÊý¶¼ÊÇÕûÊýÀàÐͶøµÚ¶þ¸ö²ÎÊýÊǸºÊý£¬ÔòÒý·¢Òì³£¡££© Èç¹ûµÚ¶þ¸ö²ÎÊýΪ¸º£¬Ôò±ØÐëÊ¡ÂÔµÚÈý¸ö²ÎÊý¡£ Èç¹û´æÔÚz£¬ÔòxºÍy±ØÐëÊÇÕûÊýÀàÐÍ£¬y±ØÐëÊǷǸºµÄ¡£ £¨Õâ¸öÏÞÖÆÊÇÔÚPython 2.2ÖÐÌí¼ÓµÄ¡£ÔÚPython 2.1ºÍ֮ǰ£¬¸¡¶¯3²ÎÊýpow£¨£©¸ù¾Ý¸¡µãÉáÈëʹʷµ»ØÒÀÀµÓÚƽ̨µÄ½á¹û¡££©
Ò²ÐíÄãÎ¥·´Á˴󵨵IJ¿·Ö£¿