Python 3 Syntax
This lesson has Python 3 Trinkets which are executable scripts in the web browser. Click the play button as shown below to execute the python code:
Comments
Commenting your code is extremely important and that is why we are starting comments! A comment is preceded with a hash # symbol:
# This is a python single line comment
You can write comments on their own line or directly after a command:
print("Hello Server Academy!") # This is a comment after a command
You can also create multiline comments using triple quotes:
"""
This is a multiline comment
You can have a bunch of non-executable stuff here.
1) Like this
2) Or this..
3) Or this
"""
When you're writing code you MUST use comments to explain what your code is doing so you (in a later time) and other developers will know what the code you write is doing.
Indentation
Python relies on indentation (the white space before a series of commands) to indicate blocks of code. See the below example of how Python cannot execute the code below:
if 0 == 0:
print("0 is equal to 0") # Inpropper indentation
To fix this code you need to add some indentations like that shown below. Try copying the code below into the editor above.
Note that it doesn't matter how many spaces you use, as long as you pick a number of spaces and stick with it. The standard is 4 spaces, so it's a good idea to use that.
if 0 == 0:
print("0 is equal to 0")
if 0 == 0:
print("0 is equal to 0")
if 0 == 0:
print("0 is equal to 0")
To continue the if code block, we will use the same indentation until we are ready to complete the code block:
if 0 == 0:
print("0 is equal to 0")
print("This is a valid example ")
This is an example of invalid indentation
if 0 == 0:
print("0 is equal to 0")
print("This code is executed inside the if statement code block") # Invalid indentation
Saving Progress...
Python 3 Fundamentals
Installing Python on Windows • 1hr 17min
0 / 4 lessons complete
Section Overview
Free Preview Lesson
Text | 1 min
Downloading and Installing Python on Windows
Free Preview Lesson
Text | 8 min
Installing and configuring VS Code for Python
Free Preview Lesson
Text | 8 min
Lab: Installing Python
Free Preview Lesson
Devops Lab | 60
Python Basics • 28min
0 / 7 lessons complete
Python Variables • 41min
0 / 8 lessons complete
Section Overview
Free Preview Lesson
Text | 4 min
Casting
Free Preview Lesson
Text | 4 min
Strings
Free Preview Lesson
Text | 5 min
Booleans
Free Preview Lesson
Text | 8 min
User Input
Free Preview Lesson
Text | 2 min
Numbers
Free Preview Lesson
Text | 7 min
NoneType
Free Preview Lesson
Text | 5 min
Assignment: Write a Mad Libs Script
Free Preview Lesson
Text | 6 min
Even more Python Variables! • 41min
0 / 6 lessons complete
Python Lists
Free Preview Lesson
Text | 8 min
Python Tuples
Free Preview Lesson
Text | 7 min
Python Sets
Free Preview Lesson
Text | 7 min
Frozensets
Free Preview Lesson
Text | 6 min
Dictionaries
Free Preview Lesson
Text | 8 min
Iterator and Iterable
Free Preview Lesson
Text | 5 min
Conditional Statements • 15min
0 / 3 lessons complete
Section Overview
Free Preview Lesson
Text | 2 min
If Statements
Free Preview Lesson
Text | 6 min
Try, Except
Free Preview Lesson
Text | 7 min
Writing Functions • 30min
0 / 5 lessons complete
Section Overview
Free Preview Lesson
Text | 3 min
Defining Functions
Free Preview Lesson
Text | 4 min
Importing functions from another file
Free Preview Lesson
Text | 4 min
Assignment: Rock, paper, scissors
Free Preview Lesson
Text | 12 min
Assignment: Count Dictionary Words
Free Preview Lesson
Text | 7 min
Python Loops • 23min
0 / 5 lessons complete
Section Overview
Free Preview Lesson
Text | 2 min
For In Loops
Free Preview Lesson
Text | 5 min
While Loops
Free Preview Lesson
Text | 5 min
Nested Loops
Free Preview Lesson
Text | 3 min
Python Loops Challenge!
Free Preview Lesson
Text | 8 min
Python PIP and Modules • 18min
0 / 4 lessons complete
Section Overview
Free Preview Lesson
Text | 3 min
Installing Python PIP
Free Preview Lesson
Text | 4 min
Installing Modules with PIP
Free Preview Lesson
Text | 5 min
Importing Modules
Free Preview Lesson
Text | 6 min
RegEx • 26min
0 / 4 lessons complete
Section Overview
Free Preview Lesson
Text | 4 min
Regex 101
Free Preview Lesson
Text | 10 min
Importing Regex and manipulating strings
Free Preview Lesson
Text | 7 min
Regex Challenge!
Free Preview Lesson
Text | 5 min
Working with APIs • 12min
0 / 3 lessons complete
Making HTTP Requests
Free Preview Lesson
Text | 3 min
Working with JSON
Free Preview Lesson
Text | 5 min
Get your weather with the OpenWeatherMap
Free Preview Lesson
Text | 4 min
Course Conclusion • 2min
0 / 1 lessons complete