4. Python Basic Syntax
In order for the Python interpreter to process and execute
your instructions properly, you
must write your code in the format that it can understand.
In programming, syntax refers
to the set of rules that define the correct form,
combination, and sequence of words and
symbols
Fahad
Ashrafi
6. Key Words
• PLEASE NOTE
• All the keywords except True, False and None are in lowercase
and they must be
• written as it is.
• Keyword are case sensitive.
• Example : is print, for, in,
Fahad
Ashrafi
7. Python’s Identifiers
An identifier is a name given to a variable, class, function, string, list,
dictionary, module, and other objects. In python, it helps differentiating one
entity from another.
Fahad
Ashrafi
8. Using Quotation Marks
Quotation marks are used to indicate string literals. You can use single (΄), double
(“), or triple (”’) quotes but you must observe consistency by using the same
quotation marks to begin and end the string.
Examples:
‘Fahad’
“Karachi”
”‘age:”’
Fahad
Ashrafi
9. Statements
Statements are expressions that you write within a program which are, in turn,
read and executed by the Python interpreter. Python supports statements such
as if statement, for statement, while statement, break statement, and
assignment statements.
Fahad
Ashrafi
10. Variables
A variable is a reserved memory location that can be used to store values.
This means that when you create a variable you reserve some space in the
memory.
Fahad
Ashrafi
11. Memory Location
To check the memory location of the above variables, you’ll use the id() operator.
But first, open you IDLE and type the variables and their values showed above.
Figure 7. Here are the variable assignments statements.
Now you can type these assignments:
>>>id(employee)
>>>id(score)
>>>id(counter)
>>>id(comment)
Once you
Fahad
Ashrafi