🐍Python Basics – Syntax And Semantics

Syntax refers to the set of rules that defines the combinations of symbols that are considered to be correctly structured programs in a language. In simpler terms, syntax is about the correct arrangement of words and symbols in code.

Semantics refers to the meaning or interpretation of the symbols, characters, and commands in a language. It is about what the code is supposed to do when it runs.

Basic Syntax Rules In Python

1. Case sensitivity

Python is case sensitive

2. Multiline Comment

[code language="python"]
# # this is a single line comment
[/code]
[code language="python"]
‘’’

this is a multi line comment 

welcome to my page

‘’’
[/code]

The triple quotes usually don’t work on jupiter files, they only work on .py files

3. Indentation

Python uses indentation to define blocks of code.

Consistent use of spaces (commonly 4) or a tab is required.

Indentation in Python is used to define the structure and hierarchy of the
that use braces {} to delimit blocks of code,

Python uses indentation to determine
that all the statements within a block must be indented at the same level.

4. Line continuation

Use a backslash to continue a statement to the next line

[code language="python"]
total=1+2+3+4+5+6+7+\
+5+6
print(total)
[/code]

5. Multiple statements on a single line

[code language="python"]
x=5;y=10; z=x+y
print(z)
[/code]

6. Semnatics in python

The type of a variable is not declared when the variable is assigned, but it’s set during runtime according to assignment value.

name = 'FirstName'

Here we do not declare that the name is a string, but it’s set by the value.

Leave a Reply

Your email address will not be published. Required fields are marked *