Welcome to the Python 3 Basics tutorial! If you are new to Python or looking to brush up on your skills, this guide is for you. Below, you will find an overview of the fundamental concepts of Python 3.

Table of Contents

Introduction to Python 3

Python is a high-level, interpreted programming language. It is known for its simplicity and readability. Python 3 is the latest major version of Python, which includes many improvements over Python 2.

Python Logo

Basic Syntax

Python has a very simple syntax. Here is an example of a basic Python program:

print("Hello, World!")

In this program, print() is a built-in function that outputs the text "Hello, World!" to the console.

Variables and Data Types

Python is dynamically typed, which means you do not need to declare the data type of a variable. Python will infer the type based on the value assigned to it.

x = 10       # Integer
y = 3.14     # Float
name = "Alice"  # String

Control Structures

Python uses control structures to control the flow of execution. The most common control structures are:

  • If-else statements for conditional execution.
  • For loops for iterating over a sequence.
  • While loops for repeating a block of code until a condition is met.
# If-else statement
if x > y:
    print("x is greater than y")
else:
    print("x is less than or equal to y")

# For loop
for i in range(5):
    print(i)

# While loop
while x < 10:
    print(x)
    x += 1

Functions

Functions are a way to organize your code into reusable blocks. Here is an example of a simple function:

def greet(name):
    return "Hello, " + name + "!"

print(greet("Alice"))

Further Reading

If you have completed this tutorial and are ready to dive deeper into Python, we recommend checking out our advanced Python tutorials. Learn more about advanced Python concepts and techniques in our Advanced Python Tutorial.