What does underscore in a number mean? [duplicate]

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












13
















This question already has an answer here:



  • How to use digit separators for Python integer literals?

    4 answers



  • What do 1_000 and 100_000 mean? [duplicate]

    2 answers



  • Declaring a number in Python. Possible to emphasize thousand?

    2 answers



I am wondering why the following variable is treated like a number?



a = 1_000_000
print (a)



1000000




Shouldn't print(a) return 1_000_000?










share|improve this question













marked as duplicate by coldspeed python
Users with the  python badge can single-handedly close python questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Jan 2 at 16:43


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.



















    13
















    This question already has an answer here:



    • How to use digit separators for Python integer literals?

      4 answers



    • What do 1_000 and 100_000 mean? [duplicate]

      2 answers



    • Declaring a number in Python. Possible to emphasize thousand?

      2 answers



    I am wondering why the following variable is treated like a number?



    a = 1_000_000
    print (a)



    1000000




    Shouldn't print(a) return 1_000_000?










    share|improve this question













    marked as duplicate by coldspeed python
    Users with the  python badge can single-handedly close python questions as duplicates and reopen them as needed.

    StackExchange.ready(function()
    if (StackExchange.options.isMobile) return;

    $('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
    var $hover = $(this).addClass('hover-bound'),
    $msg = $hover.siblings('.dupe-hammer-message');

    $hover.hover(
    function()
    $hover.showInfoMessage('',
    messageElement: $msg.clone().show(),
    transient: false,
    position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
    dismissable: false,
    relativeToBody: true
    );
    ,
    function()
    StackExchange.helpers.removeMessages();

    );
    );
    );
    Jan 2 at 16:43


    This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

















      13












      13








      13









      This question already has an answer here:



      • How to use digit separators for Python integer literals?

        4 answers



      • What do 1_000 and 100_000 mean? [duplicate]

        2 answers



      • Declaring a number in Python. Possible to emphasize thousand?

        2 answers



      I am wondering why the following variable is treated like a number?



      a = 1_000_000
      print (a)



      1000000




      Shouldn't print(a) return 1_000_000?










      share|improve this question















      This question already has an answer here:



      • How to use digit separators for Python integer literals?

        4 answers



      • What do 1_000 and 100_000 mean? [duplicate]

        2 answers



      • Declaring a number in Python. Possible to emphasize thousand?

        2 answers



      I am wondering why the following variable is treated like a number?



      a = 1_000_000
      print (a)



      1000000




      Shouldn't print(a) return 1_000_000?





      This question already has an answer here:



      • How to use digit separators for Python integer literals?

        4 answers



      • What do 1_000 and 100_000 mean? [duplicate]

        2 answers



      • Declaring a number in Python. Possible to emphasize thousand?

        2 answers







      python python-3.x






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jan 2 at 16:24









      sophrossophros

      2,2381626




      2,2381626




      marked as duplicate by coldspeed python
      Users with the  python badge can single-handedly close python questions as duplicates and reopen them as needed.

      StackExchange.ready(function()
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function()
      $hover.showInfoMessage('',
      messageElement: $msg.clone().show(),
      transient: false,
      position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
      dismissable: false,
      relativeToBody: true
      );
      ,
      function()
      StackExchange.helpers.removeMessages();

      );
      );
      );
      Jan 2 at 16:43


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






      marked as duplicate by coldspeed python
      Users with the  python badge can single-handedly close python questions as duplicates and reopen them as needed.

      StackExchange.ready(function()
      if (StackExchange.options.isMobile) return;

      $('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
      var $hover = $(this).addClass('hover-bound'),
      $msg = $hover.siblings('.dupe-hammer-message');

      $hover.hover(
      function()
      $hover.showInfoMessage('',
      messageElement: $msg.clone().show(),
      transient: false,
      position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
      dismissable: false,
      relativeToBody: true
      );
      ,
      function()
      StackExchange.helpers.removeMessages();

      );
      );
      );
      Jan 2 at 16:43


      This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
























          3 Answers
          3






          active

          oldest

          votes


















          21














          With Python 3.6 (and PEP-515) there is a new convenience notation for big numbers introduced which allows you to divide groups of digits in the number literal so that it is easier to read them.



          Examples of use:



          a = 1_00_00 # you do not need to group digits by 3!
          b = 0xbad_c0ffee # you can make fun with hex digit notation
          c = 0b0101_01010101010_0100 # works with binary notation
          f = 1_000_00.0
          print(a,b,c,f)



          10000



          50159747054



          174756



          100000.0




          print(int('1_000_000'))
          print(int('0xbad_c0ffee', 16))
          print(int('0b0101_01010101010_0100',2))
          print(float('1_000_00.0'))



          1000000



          50159747054



          174756



          100000.0




          A = 1__000 # SyntaxError: invalid token





          share|improve this answer
































            2














            Python allows you to put underscores in numbers for convenience. They're used to separate groups of numbers, much like commas do in non-programming. Underscores are completely ignored in numbers, much like comments. So this:



            x = 1_000_000


            is interpreted to be the same as this:



            x = 1000000


            However, you can't put two underscores right next to each other like this:



            x = 1__000__000 #SyntaxError





            share|improve this answer






























              2














              In English speaking countries, commas are generally used as thousand separators, while in many other countries, periods are used as thousand separators. Given the differing conventions, and the fact that both commas and periods are used for other things in Python, it was decided to use underscores as separators.






              share|improve this answer























              • In India, which is English speaking, the separator is not placed at thousands: en.wikipedia.org/wiki/Crore

                – Neil G
                Jan 9 at 22:37

















              3 Answers
              3






              active

              oldest

              votes








              3 Answers
              3






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              21














              With Python 3.6 (and PEP-515) there is a new convenience notation for big numbers introduced which allows you to divide groups of digits in the number literal so that it is easier to read them.



              Examples of use:



              a = 1_00_00 # you do not need to group digits by 3!
              b = 0xbad_c0ffee # you can make fun with hex digit notation
              c = 0b0101_01010101010_0100 # works with binary notation
              f = 1_000_00.0
              print(a,b,c,f)



              10000



              50159747054



              174756



              100000.0




              print(int('1_000_000'))
              print(int('0xbad_c0ffee', 16))
              print(int('0b0101_01010101010_0100',2))
              print(float('1_000_00.0'))



              1000000



              50159747054



              174756



              100000.0




              A = 1__000 # SyntaxError: invalid token





              share|improve this answer





























                21














                With Python 3.6 (and PEP-515) there is a new convenience notation for big numbers introduced which allows you to divide groups of digits in the number literal so that it is easier to read them.



                Examples of use:



                a = 1_00_00 # you do not need to group digits by 3!
                b = 0xbad_c0ffee # you can make fun with hex digit notation
                c = 0b0101_01010101010_0100 # works with binary notation
                f = 1_000_00.0
                print(a,b,c,f)



                10000



                50159747054



                174756



                100000.0




                print(int('1_000_000'))
                print(int('0xbad_c0ffee', 16))
                print(int('0b0101_01010101010_0100',2))
                print(float('1_000_00.0'))



                1000000



                50159747054



                174756



                100000.0




                A = 1__000 # SyntaxError: invalid token





                share|improve this answer



























                  21












                  21








                  21







                  With Python 3.6 (and PEP-515) there is a new convenience notation for big numbers introduced which allows you to divide groups of digits in the number literal so that it is easier to read them.



                  Examples of use:



                  a = 1_00_00 # you do not need to group digits by 3!
                  b = 0xbad_c0ffee # you can make fun with hex digit notation
                  c = 0b0101_01010101010_0100 # works with binary notation
                  f = 1_000_00.0
                  print(a,b,c,f)



                  10000



                  50159747054



                  174756



                  100000.0




                  print(int('1_000_000'))
                  print(int('0xbad_c0ffee', 16))
                  print(int('0b0101_01010101010_0100',2))
                  print(float('1_000_00.0'))



                  1000000



                  50159747054



                  174756



                  100000.0




                  A = 1__000 # SyntaxError: invalid token





                  share|improve this answer















                  With Python 3.6 (and PEP-515) there is a new convenience notation for big numbers introduced which allows you to divide groups of digits in the number literal so that it is easier to read them.



                  Examples of use:



                  a = 1_00_00 # you do not need to group digits by 3!
                  b = 0xbad_c0ffee # you can make fun with hex digit notation
                  c = 0b0101_01010101010_0100 # works with binary notation
                  f = 1_000_00.0
                  print(a,b,c,f)



                  10000



                  50159747054



                  174756



                  100000.0




                  print(int('1_000_000'))
                  print(int('0xbad_c0ffee', 16))
                  print(int('0b0101_01010101010_0100',2))
                  print(float('1_000_00.0'))



                  1000000



                  50159747054



                  174756



                  100000.0




                  A = 1__000 # SyntaxError: invalid token






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Jan 2 at 16:31

























                  answered Jan 2 at 16:24









                  sophrossophros

                  2,2381626




                  2,2381626























                      2














                      Python allows you to put underscores in numbers for convenience. They're used to separate groups of numbers, much like commas do in non-programming. Underscores are completely ignored in numbers, much like comments. So this:



                      x = 1_000_000


                      is interpreted to be the same as this:



                      x = 1000000


                      However, you can't put two underscores right next to each other like this:



                      x = 1__000__000 #SyntaxError





                      share|improve this answer



























                        2














                        Python allows you to put underscores in numbers for convenience. They're used to separate groups of numbers, much like commas do in non-programming. Underscores are completely ignored in numbers, much like comments. So this:



                        x = 1_000_000


                        is interpreted to be the same as this:



                        x = 1000000


                        However, you can't put two underscores right next to each other like this:



                        x = 1__000__000 #SyntaxError





                        share|improve this answer

























                          2












                          2








                          2







                          Python allows you to put underscores in numbers for convenience. They're used to separate groups of numbers, much like commas do in non-programming. Underscores are completely ignored in numbers, much like comments. So this:



                          x = 1_000_000


                          is interpreted to be the same as this:



                          x = 1000000


                          However, you can't put two underscores right next to each other like this:



                          x = 1__000__000 #SyntaxError





                          share|improve this answer













                          Python allows you to put underscores in numbers for convenience. They're used to separate groups of numbers, much like commas do in non-programming. Underscores are completely ignored in numbers, much like comments. So this:



                          x = 1_000_000


                          is interpreted to be the same as this:



                          x = 1000000


                          However, you can't put two underscores right next to each other like this:



                          x = 1__000__000 #SyntaxError






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Jan 2 at 16:28









                          pizza static void mainpizza static void main

                          1,6541924




                          1,6541924





















                              2














                              In English speaking countries, commas are generally used as thousand separators, while in many other countries, periods are used as thousand separators. Given the differing conventions, and the fact that both commas and periods are used for other things in Python, it was decided to use underscores as separators.






                              share|improve this answer























                              • In India, which is English speaking, the separator is not placed at thousands: en.wikipedia.org/wiki/Crore

                                – Neil G
                                Jan 9 at 22:37















                              2














                              In English speaking countries, commas are generally used as thousand separators, while in many other countries, periods are used as thousand separators. Given the differing conventions, and the fact that both commas and periods are used for other things in Python, it was decided to use underscores as separators.






                              share|improve this answer























                              • In India, which is English speaking, the separator is not placed at thousands: en.wikipedia.org/wiki/Crore

                                – Neil G
                                Jan 9 at 22:37













                              2












                              2








                              2







                              In English speaking countries, commas are generally used as thousand separators, while in many other countries, periods are used as thousand separators. Given the differing conventions, and the fact that both commas and periods are used for other things in Python, it was decided to use underscores as separators.






                              share|improve this answer













                              In English speaking countries, commas are generally used as thousand separators, while in many other countries, periods are used as thousand separators. Given the differing conventions, and the fact that both commas and periods are used for other things in Python, it was decided to use underscores as separators.







                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered Jan 2 at 16:36









                              AcccumulationAcccumulation

                              1,38529




                              1,38529












                              • In India, which is English speaking, the separator is not placed at thousands: en.wikipedia.org/wiki/Crore

                                – Neil G
                                Jan 9 at 22:37

















                              • In India, which is English speaking, the separator is not placed at thousands: en.wikipedia.org/wiki/Crore

                                – Neil G
                                Jan 9 at 22:37
















                              In India, which is English speaking, the separator is not placed at thousands: en.wikipedia.org/wiki/Crore

                              – Neil G
                              Jan 9 at 22:37





                              In India, which is English speaking, the separator is not placed at thousands: en.wikipedia.org/wiki/Crore

                              – Neil G
                              Jan 9 at 22:37


                              Popular posts from this blog

                              How to check contact read email or not when send email to Individual?

                              Displaying single band from multi-band raster using QGIS

                              How many registers does an x86_64 CPU actually have?