Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #53199

Re: semicolon at end of python's statements

Date 2013-08-28 19:35 -0500
From Tim Chase <python.list@tim.thechases.com>
Subject Re: semicolon at end of python's statements
References <1377735506.18906.15.camel@debian>
Newsgroups comp.lang.python
Message-ID <mailman.334.1377736483.19984.python-list@python.org> (permalink)

Show all headers | View raw


On 2013-08-29 04:48, Mohsen Pahlevanzadeh wrote:
> I'm C++ programmer and unfortunately put semicolon at end of my
> statements in python.
> 
> Quesion:
> What's really defferences between putting semicolon and don't put?

From a technical standpoint, nothing (see below).  From a "readability
on the part of other programmers" standpoint, it's bad practice.  So
if you're coding for yourself, do whichever makes you happy.  If you
want to interact with other Python developers and don't want to make
them grumpy, remove them.

-tkc



>>> def with_semis():
...     print 1;
...     print 2;
...     print 3;
... 
>>> def without_semis():
...     print 1
...     print 2
...     print 3
... 
>>> import dis
>>> dis.dis(with_semis)
  2           0 LOAD_CONST               1 (1)
              3 PRINT_ITEM          
              4 PRINT_NEWLINE       

  3           5 LOAD_CONST               2 (2)
              8 PRINT_ITEM          
              9 PRINT_NEWLINE       

  4          10 LOAD_CONST               3 (3)
             13 PRINT_ITEM          
             14 PRINT_NEWLINE       
             15 LOAD_CONST               0 (None)
             18 RETURN_VALUE        
>>> dis.dis(without_semis)
  2           0 LOAD_CONST               1 (1)
              3 PRINT_ITEM          
              4 PRINT_NEWLINE       

  3           5 LOAD_CONST               2 (2)
              8 PRINT_ITEM          
              9 PRINT_NEWLINE       

  4          10 LOAD_CONST               3 (3)
             13 PRINT_ITEM          
             14 PRINT_NEWLINE       
             15 LOAD_CONST               0 (None)
             18 RETURN_VALUE        

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: semicolon at end of python's statements Tim Chase <python.list@tim.thechases.com> - 2013-08-28 19:35 -0500

csiph-web