Introduction

Welcome to our first lesson of the Python introductory course! Today, we will uncover the simplicity and power of Python, a universally esteemed programming language renowned for its expressiveness and readability. We'll learn and practice in the CodeSignal environment, where the Python libraries are pre-installed. By the end of this lesson, you'll grasp the foundational aspects of Python and be able to execute your very first Python code. Intriguing, isn't it?

Understanding Python Syntax

Every language, whether it's English, Spanish, or Python, operates under a unique syntax. This cohesive framework consists of rules and principles that delineate what is grammatically correct. Similarly, Python's syntax describes how Python programs should be composed and structured.

Let's start with something simple! Statements are instructions that a Python interpreter can execute. For example:

print("Hello, and welcome to the Python World!")

In this statement, print() is a function that Python provides to print the provided input to the console, and "Hello, and welcome to the Python World!" is a string that is printed on the console.

Explaining Comments in Python

Coding is a form of art, and akin to every artist, coders leave reflections and significant explanations in their code in the form of comments. Comments are annotations or explanations providing additional insights about the code. They make your code more informative and demonstrative to others (or even to your future self). Comments do not affect your code execution or its outcome in any way but are helpful to better understand what's happening in the code.

Python features two types of comments: single-line and multi-line. Here is what they look like:

# This is a single-line comment in Python.

'''
This is a 
multi-line comment in Python.
'''
"""
This is another
multi-line comment in Python.
"""

In this Python code snippet, you see a single-line comment initiated with #, and a block of lines enclosed within triple quotes (single or double), forming a multi-line comment.

Introducing Indentation in Python

Python uniquely approaches code organization by using indentation rather than braces or keywords to determine blocks of code. This method enhances Python's readability and enforces a uniform coding style. Here's an example (you don't have to understand the meaning of the if block for now, we'll cover it in the next lessons):

if 5 > 2:
    print("Five is indeed greater than two!") # this belongs to the if block
print("End of program") # this does not belong to the if block

In this code snippet, due to the indentation, the first print statement belongs to the if block, while the second print statement, which is not indented, falls outside the if block.

Sign up
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal