0

I am fairly good at python but I am wondering if using semi colons is looked down upon in any way. When I see code snippets online or I look at friends code etc I don't see them. If they are looked down upon, why? I don't see a problem with them. I would use them like this for example:

print("What you do want {}?".format(name));choice = input(">> ")
Throupy
  • 21
  • 6
  • Why does it need to be on one line would be my question – EdChum Sep 28 '18 at 15:47
  • 1
    They add nothing. Why use them? Use `choice = input("What you do want {}?".format(name)\n>> ")` instead. *>looking down on them<* See [python-what-does-a-semicolon-do](https://stackoverflow.com/questions/12335358/python-what-does-a-semicolon-do) – Patrick Artner Sep 28 '18 at 15:47
  • 2
    Python has established coding style guidelines https://www.python.org/dev/peps/pep-0008/? – John Sep 28 '18 at 15:50
  • See [here](https://stackoverflow.com/questions/8236380/why-is-semicolon-allowed-in-this-python-snippet) – pushkin Nov 05 '18 at 14:46

1 Answers1

2

It's normally discouraged as it detracts from readability, from PEP8:

Compound statements (multiple statements on the same line) are generally discouraged.

Yes:

if foo == 'blah':
    do_blah_thing()
do_one()
do_two()
do_three()

Rather not:

if foo == 'blah': do_blah_thing()
do_one(); do_two(); do_three()

While sometimes it's okay to put an if/for/while with a small body on the same line, never do this for multi-clause statements. Also avoid folding such long lines!

Rather not:

if foo == 'blah': do_blah_thing()
for x in lst: total += x
while t < 10: t = delay()

Definitely not:

if foo == 'blah': do_blah_thing()
else: do_non_blah_thing()

try: something()
finally: cleanup()

do_one(); do_two(); do_three(long, argument,
                             list, like, this)

if foo == 'blah': one(); two(); three()
Chris_Rands
  • 38,994
  • 14
  • 83
  • 119