Python
Python Syntax
• Python syntax can be executed by writing directly in
the Command Line
Python Comments
• Comments can be used to explain Python code.
• Comments can be used to make the code more readable.
• Comments can be used to prevent execution when testing
code.
Creating a Comment
• Comments starts with a #, and Python will ignore them
Multiline Comments
• To add a multiline comment you could insert a # for each line
Multiline Comments
• you can add a multiline string (triple quotes) in your
code, and place your comment inside it
Variables
Creating Variables
Casting
Type
Case-Sensitivity of Python Variables
Single or Double Quotes?
String variables can be declared either by using single or
double quotes.
Variable Names
• A variable name must start with a letter or the underscore
character
• A variable name cannot start with a number
• A variable name can only contain alpha-numeric characters
and underscores (A-z, 0-9, and _ )
• Variable names are case-sensitive (age, Age and AGE are
three different variables)
• A variable name cannot be any of the Python keywords.
Python keywords
Legal variable names
Illegal variable names
Multi Words Variable Names
Camel Case
Each word, except the first, starts with a capital
letter.
myVariableName = “tpt"
Assign Multiple Values
One Value to Multiple Variables
The Python print() function is often used to output variables.
Mathematical Operator
(a +b)² = a² + b² + 2ab
Thank You