Here are some of the basic syntax rules for Python:
- Python is case-sensitive, which means that
helloare treated as two different variables.
- Python uses indentation to define blocks of code, rather than curly braces. The standard indentation is 4 spaces, but some people prefer to use 2 spaces or a tab. It is important to be consistent with your indentation, as it affects the way the code is parsed.
- Python uses
#to indicate the beginning of a comment. Everything after the
#on the same line is ignored by the interpreter.
- Python uses quotation marks (either single or double) to indicate the beginning and end of a string. If you need to include a quotation mark within a string, you can use the opposite type of quotation mark to define the string, or you can use the
\character to escape the quotation mark.
Here is an example of some simple Python code:
# This is a comment # This is a string message = "Hello, world!" # This is a variable x = 10 # This is a conditional statement if x > 0: print(message)