What does underscore in a number mean? [duplicate]












9















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();
}
);
});
});
9 mins ago


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.




















    9















    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();
    }
    );
    });
    });
    9 mins ago


    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.


















      9












      9








      9








      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 28 mins ago









      sophros

      2,1161623




      2,1161623




      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();
      }
      );
      });
      });
      9 mins ago


      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();
      }
      );
      });
      });
      9 mins ago


      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


















          16














          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































            1














            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





























              1














              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




























                3 Answers
                3






                active

                oldest

                votes








                3 Answers
                3






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes









                16














                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




























                  16














                  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


























                    16












                    16








                    16






                    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 21 mins ago

























                    answered 28 mins ago









                    sophros

                    2,1161623




                    2,1161623

























                        1














                        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


























                          1














                          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
























                            1












                            1








                            1






                            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 24 mins ago









                            David the third

                            1,3851723




                            1,3851723























                                1














                                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


























                                  1














                                  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
























                                    1












                                    1








                                    1






                                    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 17 mins ago









                                    Acccumulation

                                    1,36529




                                    1,36529















                                        Popular posts from this blog

                                        Understanding the information contained in the Deep Space Network XML data?

                                        Ross-on-Wye

                                        Eastern Orthodox Church