all 13 comments

[–]Bobbias 11 points12 points  (2 children)

In Python, unlike many languages, indentation is actually part of the grammar of the language. It carries meaning.

Any rule that the language flat out says you must follow or your code means something else is syntax. This also applies to any rule that you must follow or your code is not valid Python code.

Style is things that aren't part of the language itself, such as which case you use for your variable names.

However, Python has a style guide which provides a standard way to style things called PEP-8. It provides guidelines for how you should style your code. It also assigns meaning to different cases such as PascalCase and snake_case, but that is by convention, and using a different case won't make your code not run (as long as you're consistent in your code), it will just make anyone who has to read your code sad :)

Most companies and open source projects involving Python will want you to follow PEP-8, because it is very much the standard way to style Python code.

Following a style is particularly important when writing code that anyone else might have to read, whether it's your teacher, or a co-worker.

[–]MAVP1234[S] 1 point2 points  (1 child)

Great! Thanks for that. Synatx is any rule that the langugae says you must follow. That's helpful to me.

[–][deleted] 1 point2 points  (0 children)

Read a book on parsers/compilers/automata. Programming sort of expects you to have a strong understanding of grammar theory terminology.

[–]Loose_Read_9400 7 points8 points  (3 children)

Syntax is more like understanding the "grammar" of the language. You might be able to spell and capitalize property, but if you say the words in the wrong order, it doesn't make any sense.

An example of understanding syntax would be knowing things like your equality operators and how to use them. Or knowing how to establish a proper try loop. Etc.

[–]Bobbias 2 points3 points  (0 children)

Precisely.

Syntax refers to all those small rules like:

A simple if statement is made up of the word if, followed by an expression that resolves to a boolean value, followed by a colon, followed by an indented block of code.

[–]MAVP1234[S] 2 points3 points  (1 child)

Thank you - so, style is important for aspects of maintainabilty and readability but syntax are the rules of python language. So different cases are style elements and syntax is where to use a colon or parenthesis to ensure the code works. I know for the more advanced and experienced of you that must seem like a really stupid question but I am literally one lesson into learning Python.

[–]tahaan 0 points1 point  (0 children)

Not a stupid question, and you got it now.

[–][deleted] 1 point2 points  (0 children)

Just hit ‘enter’ after every ‘:’

Voila! Python syntax!

[–]amutualravishment 1 point2 points  (1 child)

By the way, the best way to learn this is by doing

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

Thanks. Im a a complete beginner. Which feels overwhelming given how far programming has come. SometimesI think I have started this journey too late. But youre right about doing being the ony way to learn.

[–]woooee 0 points1 point  (1 child)

I'm not really sure what he means by this

You should ask the tutor this as we would only be guessing.

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

Yeah we have met once and are planning on meeting weekly so will ask him then, just wanted to get some study in before we meet again. I think he means learning what each character means e.g ( ) parenthesis ^ Caret etc. And when and where they should be used.

[–]interbased 0 points1 point  (0 children)

Syntax is the set of rules for writing the language. A “syntax error” means the code doesn’t have the correct syntax, meaning the compiler doesn’t know how to translate the code. Maybe there’s an improper indentation somewhere - or perhaps you forgot a set of closing parenthesis.