µ±Ç°Î»Ö㺠´úÂëÃÔ >> python >> ΪʲôPython˵powÖ»ÓÐ2¸ö²ÎÊý
  Ïêϸ½â¾ö·½°¸

ΪʲôPython˵powÖ»ÓÐ2¸ö²ÎÊý

Èȶȣº41   ·¢²¼Ê±¼ä£º2023-06-13 14:01:00.0

Ϊʲôpython¸æËßÎÒ¡°TypeError£ºpowÔ¤ÆÚ2¸ö²ÎÊý£¬µÃµ½3¡±¾¡¹ÜËüÔÚIDLEÖй¤×÷£¨ÓÐʱËü¸æËßÎÒÔÚIDLEÖÐÒ²ÊÇÈç´Ë£©£¿ ÎÒÖ»ÊÇ×öpow(a,b,c) ¡£ ÎҵijÌÐòºÜ¶Ì£¬ÎÒ²»»áËæʱ¸ü¸ÄpowµÄ¶¨Ò壬ÒòΪÎÒÐèҪʹÓÃËüÀ´½øÐÐһЩȡÃÝ¡£

×¢Ò⣺ÕâÊÇÀ´×Ô__builtin__µÄpow £¬¶ø²»ÊÇMath

ÄÚÖÃpowÐèÒªÁ½¸ö»òÈý¸ö²ÎÊý¡£ Èç¹ûÄãfrom math import *ÄÇÀïÈ¡¶ø´úÖ®µÄÊÇmathµÄpow £¬ËüÖ»ÐèÒªÁ½¸ö²ÎÊý¡£ ÎҵĽ¨ÒéÊǽøÐÐimport math £¬»òÃ÷È·ÁгöÄúÔÚµ¼ÈëÁбíÖÐʹÓõĺ¯Êý¡£ openºÍos.open·¢ÉúÀàËƵÄÎÊÌâ¡£

Èç¹ûÄãÕýÔÚʹÓÃÊýѧº¯ÊýºÜ¶à¶øÇÒÔÚpython 2.7ÖкÜÉÙʹÓÃpowµÄÈý¸ö²ÎÊý°æ±¾¾ÍÊǵ¼Èë__builtin__²¢Îª3²ÎÊýµ÷ÓÃ__builtin__ .pow

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¿·Ö£¿

  Ïà¹Ø½â¾ö·½°¸