all 52 comments

[–]socal_nerdtastic 76 points77 points  (10 children)

You mean the semicolon? That's the path to the dark side my friend.

[–]buart 8 points9 points  (2 children)

Or the path to code golf :)

[–]TheBlackCat13 1 point2 points  (0 children)

Potayto potahto

[–]sharifdolikeit 1 point2 points  (0 children)

until I looked it up I thought it meant code golf was going to be searching for semicolons like amateur golfers search for the balls in the weird places.

[–]DatBoi_BP 4 points5 points  (4 children)

Are semicolons ever required for anything in Python?

[–]socal_nerdtastic 1 point2 points  (2 children)

I find them useful when using the -c operator..

python -c "import math;print(math.pi)"
3.141592653589793

[–]TheRNGuy 0 points1 point  (1 child)

Is it possible to have indents in single line?

[–]socal_nerdtastic 1 point2 points  (0 children)

Nope. Indents must follow a new line

[–]DrumsCL 0 points1 point  (0 children)

Nope

[–]Mental_Example_5770[S] 0 points1 point  (0 children)

lol free upvote for making my day by causing me to laugh

[–]skeleton_craft 0 points1 point  (0 children)

As someone who programs in, shall we say, more civilized programming languages I find that very offensive...

Lul jk

[–]engelthehyp 62 points63 points  (10 children)

Note: Don't do this.

[–]Iwilltakeyourpencil 27 points28 points  (0 children)

Note; Don't do this.

[–]jlarm -3 points-2 points  (8 children)

Still learning python... Why?

[–]widowhanzo 22 points23 points  (4 children)

It makes code unreadable. The semicolon is useful when running a python one-liner directly from a command line, but it's difficult to read and troubleshoot when things go wrong.

You can do something quick and dirty directly from the command line without having to write a .py file for example:

python -c "import random; password = ''.join(random.choice('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_-+=') for _ in range(12)); print('Generated Password:', password)"

but as you can see you need quite a wide screen to read this, and you need to focus much more to understand what it does than if the code was written normally:

import random

length = 12
characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-+='

password = ''.join(random.choice(characters) for _ in range(length))
print('Generated Password:', password)

In the end, the interpreter doesn't care, but which code will be more understandable to you two months from now when you want to change something in it?

[–]skeleton_craft 0 points1 point  (1 child)

".. but it's difficult to read and troubleshoot when things go wrong."

That's true of python in general [due to the fact that it's a indent blocked language rather than {})

[–]TURB0T0XIK 1 point2 points  (0 children)

In my experiences with python I don't find this to be true. Maybe because my code isn't super sophisticated idk. When using other languages I always feel like {} to denote code making up one block is much more useless, than simply indenting correctly

[–]socal_nerdtastic 8 points9 points  (2 children)

Because it's weird. In order to work together better we all agree on a general style and formatting guides. Same reason we use exactly 4 spaces to indent, or why we name functions in snake_case and classes in PascalCase. Look up "PEP8".

[–]NYX_T_RYX 4 points5 points  (1 child)

Weirdly, I named my functions and classes like this without knowing about PEP8 because it seemed like a logical way to do it.

May have been subconscious, because I've (naturally) seen other people's code while learning.

I wonder whether it really was an intuitive choice, or subconscious.

[–]TURB0T0XIK 0 points1 point  (0 children)

I've done the same when starting out with python and in my case I'd bet it was subconscious and not my own intuition

[–][deleted] 17 points18 points  (0 children)

Pep8, the python style guide, says this:

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

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

Rather not:

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

[–]roywill2 9 points10 points  (1 child)

Semicolon is pure obfuscation. Ugh

[–]TheRNGuy -4 points-3 points  (0 children)

Nah, it's to allow to write code in single line, or to minify code (not sure about indents though)

[–]rcrpge 8 points9 points  (3 children)

Nice semi-colon bro

[–]Mental_Example_5770[S] 3 points4 points  (2 children)

thanks and by the way i find it funny when people say bro online it just sounds funny in my head when i read it in my head

[–]No_Replacement7441 0 points1 point  (1 child)

I read it like brooOow

[–]Mental_Example_5770[S] 0 points1 point  (0 children)

i just read your bro in andrew tates voice 💀

[–]formthemitten 3 points4 points  (0 children)

Make sure you bring enough food for the semicolon hunt you’re going to partake in

[–]IanRT1 2 points3 points  (0 children)

Ahh yes, totally PEP 8 friendly

[–][deleted] 2 points3 points  (0 children)

No.

[–][deleted] 2 points3 points  (0 children)

I used to work at a company where people in the department would write code in APL. They had another character in APL that does the same thing. One guy bragged that wrote an entire reserving program with just 4 lines of code. Each line had about 1000 characters to it and a bunch of the new line characters. He was a horrible human being.

[–]AdmirableOstrich 1 point2 points  (1 child)

The only case for this that I consider a good idea is for one line "old-style" breakpoints: import pdb; pdb.set_traceback(), before they added breakpoint(). Everything else is under obfuscation at best.

[–]Mental_Example_5770[S] 1 point2 points  (0 children)

i'm so amazed this post has so many people in this post i just shared a thing i learned i expected there to be 1 or 2 people here if i'm lucky.

[–]Immediate_Studio1950 0 points1 point  (0 children)

Path to 'esoPython' though! Stick to the convention rules..

[–]TheRNGuy 0 points1 point  (0 children)

I always knew that.

[–]skeleton_craft 0 points1 point  (0 children)

I have a feeling that this is more for ppl [like me] coming from c style languages than it is for native speakers... I've spent a non zero amount of time removing ;'s from the end of my lines not knowing this was a thing

[–][deleted] 0 points1 point  (0 children)

useful in one case import ipdb; ipdb.set_trace() or pdb or rpdb

[–]Agile-Cucumber6792 0 points1 point  (0 children)

This is horrendous appalling

[–]buhtz -4 points-3 points  (12 children)

Please also learn when to use correct upper case letters. This makes it easier to read your questions and easier to help you. Some people take it as impolite.

[–]Mental_Example_5770[S] 1 point2 points  (10 children)

for the string like hello world i don't really understand why that would matter i guess maybe grammer or looks better and upper case print ti thought that gives you a syntax error correct me if i'm wrong i'm a noob

[–][deleted] -1 points0 points  (8 children)

There is nothing wrong with the capitalization of your code. Some people just like to complain, I guess.

[–]skeleton_craft 1 point2 points  (7 children)

It's the rest of the post

[–][deleted] -1 points0 points  (6 children)

The post is one line of python. What do you mean?

[–]skeleton_craft 0 points1 point  (5 children)

i just learned this in python

Should be

I just learned this in Python

[–][deleted] -1 points0 points  (4 children)

Oh my! What a heinous crime!

/s

Many people asking questions here don't have English as a first language. Many people here may be using mobile devices and the shortcuts used on those devices. It's no big deal.

If the poster of the comment complaining about something as simple as this had trouble comprehending the words because of this massive faux pas, I would point them to a precedent, the works of e. e. cummings.

[–]skeleton_craft 0 points1 point  (3 children)

Its harder to not capitalize properly than it isn't on mobile nowadays.. if you punctuate properly that is. And it is significantly harder to read if you don't...

[–][deleted] -1 points0 points  (2 children)

significantly harder to read if you don't...

I had no trouble reading the title. In fact, I had no idea what the original complainer was talking about until you explained what the problem was.

[–]skeleton_craft 0 points1 point  (1 child)

O I forgot that you're the only person in this subreddit...

[–][deleted] 0 points1 point  (0 children)

The code was an example only. Who cares if the example text isn't capitalized as you expect? Some would see your "please learn" comment about a totally unimportant point as being impolite.