0% found this document useful (0 votes)
7 views25 pages

2 Syntax

The document provides an overview of Python syntax, including how to write comments for code readability and testing. It explains the rules for creating variables, including naming conventions and case sensitivity, as well as the use of single and double quotes for strings. Additionally, it touches on assigning multiple values and using the print() function for output.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views25 pages

2 Syntax

The document provides an overview of Python syntax, including how to write comments for code readability and testing. It explains the rules for creating variables, including naming conventions and case sensitivity, as well as the use of single and double quotes for strings. Additionally, it touches on assigning multiple values and using the print() function for output.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

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

You might also like