Python SymPy — A Short Primer

What’s SymPy Anyway?

SymPy is a Python library for symbolic computation. So instead of approximating the result of the square root of 2, it keeps the square root intact—using a symbolic representation. This helps in further processing and can lead to situations where Python has introduced a floating point precision error without need. Here’s a basic example:

import sympy

print(sqrt(3))
# sqrt(3)

The result is NOT an approximated square root of 3 like in the math package:

import math

print(math.sqrt(3))
# 1.7320508075688772

An Interactive Example

You can try it yourself in the interactive code shell:

(Just click the image to create your own code!)

How to Install SymPy?

To install SymPy in Python, simply run the following command in your shell:

pip install sympy

This works for all major operating systems (MacOS, Windows, Linux). A preliminary is to have the pip package manager installed.

(Confused by all the libraries, modules, pip, and virtual environments? Read the ultimate library guide on my blog.)

To check whether it has installed correctly, simply run the following command in your Python shell:

>>> help(sympy)
Help on package sympy:

NAME
    sympy

DESCRIPTION
    SymPy is a Python library for symbolic mathematics. It aims to become a
    full-featured computer algebra system (CAS) while keeping the code as simple
    as possible in order to be comprehensible and easily extensible.  SymPy is
    written entirely in Python. It depends on mpmath, and other external libraries
    may be optionally for things like plotting support.
    
    See the webpage for more information and documentation:
    
        https://sympy.org

PACKAGE CONTENTS
    abc
    algebras (package)
    assumptions (package)

The output validates that the sympy package has installed correctly.

Where to Go From Here?

Enough theory. Let’s get some practice!

Coders get paid six figures and more because they can solve problems more effectively using machine intelligence and automation.

To become more successful in coding, solve more real problems for real people. That’s how you polish the skills you really need in practice. After all, what’s the use of learning theory that nobody ever needs?

You build high-value coding skills by working on practical coding projects!

Do you want to stop learning with toy projects and focus on practical code projects that earn you money and solve real problems for people?

🚀 If your answer is YES!, consider becoming a Python freelance developer! It’s the best way of approaching the task of improving your Python skills—even if you are a complete beginner.

If you just want to learn about the freelancing opportunity, feel free to watch my free webinar “How to Build Your High-Income Skill Python” and learn how I grew my coding business online and how you can, too—from the comfort of your own home.

Join the free webinar now!

Leave a Comment