Skip to content

Module 1 · Introduction to Python — topic 4 of 14

Features of Python

A tour of Python’s defining features: simple syntax, dynamic typing, interpretation, portability, object orientation, automatic memory management and a rich standard library.

Beginner 14 min read·Lesson 4 of 306 in Python Programming

Learning objectives

  • Name and explain Python’s key language features
  • Show dynamic typing and automatic memory management with small examples
  • Recognise which features make Python portable

Definition

A tour of Python’s defining features: simple syntax, dynamic typing, interpretation, portability, object orientation, automatic memory management and a rich standard library.

Introduction

Every language has a personality made up of its features. Python’s features are chosen to keep code short and safe for the programmer, even if that sometimes costs a little speed.

You will meet each of these features in detail later in the course. Here the goal is to recognise them and understand what they mean in practice.

Why it matters

Knowing Python’s features tells you what you do not have to worry about. You don’t declare variable types, free memory or recompile for each operating system, which lets you concentrate on the problem itself.

Detailed explanation

Simple, readable syntax: blocks of code are marked by indentation rather than braces, and keywords are ordinary English words.

Dynamically typed: a variable is just a name that points to a value. You don’t declare its type, and the same name can later refer to a value of another type. Python checks types while the program runs.

Interpreted and interactive: you can run code line by line in the interactive shell to experiment.

Portable: the same .py file runs on Windows, macOS and Linux as long as Python is installed.

Object-oriented, but not only: everything in Python is an object, and you can write code in an object-oriented, procedural or functional style.

Automatic memory management: Python creates and frees memory for you. When nothing refers to a value any more, it is cleaned up automatically (garbage collection).

Extensible and batteries included: Python can call code written in C for speed, and comes with a large standard library.

Syntax

Python
value = 10
value = "ten"
  • The first line makes value refer to the integer 10.
  • The second line makes the same name refer to a string.
  • No type declarations are needed; this is dynamic typing.

Code examples

Dynamic typing

Python
value = 10
print(type(value).__name__)
value = "ten"
print(type(value).__name__)
Output
int
str

Everything is an object

Python
print("python".upper())
print((3.75).is_integer())
Output
PYTHON
False

Even a string literal and a number have methods you can call.

More examples

Indentation defines blocks

Python
temperatures = [31, 36, 29, 38]
for t in temperatures:
if t > 35:
print(t, "is hot")
else:
print(t, "is comfortable")
print("Done")
Output
31 is comfortable
36 is hot
29 is comfortable
38 is hot
Done

Step-by-step explanation

  • temperatures holds four whole numbers in a list.
  • The for line repeats the indented block once per temperature.
  • Inside, the if/else chooses a message; its bodies are indented one level further.
  • print("Done") is back at the left margin, so it runs once, after the loop finishes.

Expected output

Running “Indentation defines blocks” prints exactly:

TextOutput
31 is comfortable
36 is hot
29 is comfortable
38 is hot
Done

Practical applications

  • A script written on a developer’s Windows laptop runs unchanged on a Linux server.
  • Dynamic typing makes prototypes quick to write, which is why data scientists explore data in Python.
  • Libraries such as NumPy use Python’s extensibility: the heavy maths runs in fast C code.

Best practices

  • Indent with four spaces, never a mix of tabs and spaces.
  • Even though types are dynamic, keep each variable to one kind of value.
  • Let Python manage memory; focus on clear code.

Common mistakes

Mixing types without converting

Avoid

age = 20
print("Age: " + age)

Prefer

age = 20
print("Age: " + str(age))

Dynamic typing doesn’t mean automatic conversion. Joining text and a number with + raises a TypeError; convert with str() first.

Inconsistent indentation

Avoid

if True:
print("a")
print("b")

Prefer

if True:
print("a")
print("b")

Lines in the same block must line up exactly. A mismatch raises an IndentationError.

Key takeaways

  • Python is dynamically typed: names point to values of any type.
  • Indentation, not braces, groups statements into blocks.
  • Python is portable, object-oriented and manages memory automatically.

Try it yourself

  1. 1
    Assign a whole number to a variable, print its type, then assign a decimal number to the same variable and print the type again.
  2. 2
    Add a fifth temperature to the indentation example and predict the extra output line before running it.

Finished reading? Mark it complete to update your dashboard.

Suggested practice

1 question test this exact topic. Answers and explanations are revealed after you submit.

  • BeginnerHow does Python group statements into blocks?
Practise this topic