Heim  >  Fragen und Antworten  >  Hauptteil

Syntax – Für Ganzzahlen und Gleitkommazahlen in Python gibt es keine Größenbeschränkung?

Ich habe schon einmal C gelernt und lerne jetzt Python 3.5. Das Bild unten stammt von Liao Xuefengs Website

Warum gibt es für Python-Ganzzahlen und Gleitkommazahlen keine Größenbeschränkung? ? Wie werden Ganzzahlen und Gleitkommazahlen in Python gespeichert?

Bedeutet das, dass alle in Python deklarierten Ganzzahlen und Gleitkommazahlen direkt Long Long und Long Double in C entsprechen und direkt maximalen Speicher zuweisen?

某草草某草草2710 Tage vor1579

Antworte allen(2)Ich werde antworten

  • phpcn_u1582

    phpcn_u15822017-05-18 10:59:58

    Python 的整数,理论上来说只要内存放得下,可以是任意长度的(远超long long)。
    如果C的long装得下,就用long装,装不下就自动转换到大整数,这一过程对于程序员基本透明。
    而浮点数,应该就是C的double类型。

    Floating point numbers are usually implemented using double in C. ——Python官方文档

    Antwort
    0
  • PHPz

    PHPz2017-05-18 10:59:58

    在Python中,整数是只要内存够,长度是无限制的,应该是比C里面的long long大很多的。

    浮点数是用机器上的双精度(64 bit)的,提供大约17位有效数字,应该跟C里面的double类型是差不多的。

    Antwort
    0
  • StornierenAntwort