Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What are syntaxes?
#1
Hello everyone,

this is my first post in this forum, I am trying to learn python and really struggling with some things. No matter how silly my questions may sound, i am not here to troll or waste anyone's time.

Could someone please explain what syntax is or give me an example?

TIA, much appreciated.
Reply
#2
syntax is the set of rules (grammar) used to analyze the syntax of a language.
It's not a single entity.
Reply
#3
Syntax refers to the structural rules of a language. For example, an assignment statement has a variable, then an equal sign, then what you want put into that variable.
variable = 2+3
.
Some languages would require a semicolon at the end of that statement - that is the syntax required by Java, C, and others for example.
Python does not require semicolons but "whitespace" - especially indentation - matters.
So another example, the syntax for a for loop is to use the keyword "for", then a variable that will be a counter (or an underscore), the keyword "in" then an iterable and a colon. The lines that you want repeated in the loop are then indented (preferably 4 spaces). You signal the end of that loop by not indenting. That is the syntax for a for loop
for counting_item in range(4):
    print(f'In loop {counting_item}')
print('Out of loop')
So each statement has its own syntax, or format
Reply
#4
A tax you pay for your syn's Think
Reply
#5
Thank you so much for the replies and help. Really into this but my first days with any coding. Again, much appreciated
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020