Syntax and rules in Python are how the programmer should write his code, much like grammar works in languages. The compiler don’t care about the syntax – but it is important for programmers to adhere to the correct syntax, otherwise it will be very difficult for other programmers to understand your code.
As a programmer, it is important to write with the right syntax to get structured and easily understandable code. Especially in large programming projects, there are often several different programmers working in the project. Then it is extra important that everyone writes in the same way, otherwise it is impossible to get an overview of what is happening in the code. Each programming language has its own syntax and it differs slightly between different programming languages. The syntax in Python is international, so everyone follows the same standards.
The syntax in Python is international, so everyone follows the same standards.
The syntax in Java is learned gradually as you progress and learn new programming features. Therefore, in each section we show you how the syntax for that section. However, some examples to give you a hint of different syntaxes in Python:
We will go into more detail about how variables, functions and classes work in the coming chapters!
There are certain rules that the programmer must follow when programming. If you break any rule, you will get a so-called compilation error, in other words, the compiler does not understand how to translate the code, and then the computer does not know what to do. The program will then crash.
As with syntax, rules are something you learn gradually, but it is still important to start thinking about how to structure and write your programs. Some basic rules in Python is:
A hashtag # creates a comment in the code. These are ignored by the compiler. You can thus comment on your code so that it is easy to understand what is happening.
print("Hello World!") # This is the comment --> ignored by the compiler
Giving the print: