---
title: What Are Limits in SymPy?
description: Learn how to calculate limits of sequences and functions using SymPy, with practical examples and detailed explanations.
image: https://blog.rheinwerk-computing.com/hubfs/What%20Are%20Limits%20in%20SymPy.jpg
---

[![Rheinwerk Computing Logo](https://blog.rheinwerk-computing.com/hubfs/computing_logo-header.svg)](https://blog.rheinwerk-computing.com/) [Blog](https://blog.rheinwerk-computing.com)

- Books 
    - Get an overview of our wide selection of books on every relevant computing topic. 
          - [General Computing](https://www.sap-press.com/rheinwerk-computing/general-computing/)
          - [DevOps](https://www.sap-press.com/rheinwerk-computing/devops/)
          - [Programming Languages](https://www.sap-press.com/rheinwerk-computing/programming-languages/)
          - [Security](https://www.sap-press.com/rheinwerk-computing/security/)
          - [Software Development](https://www.sap-press.com/rheinwerk-computing/software-development/)
- Book Subscription 
    - Get unlimited access to all Rheinwerk Computing books! 
          - [Programming Subscription](https://sap-press.com/subscriptions/)

[What Is?](https://blog.rheinwerk-computing.com/tag/what-is)

# What Are Limits in SymPy?

![Rheinwerk Computing](https://blog.rheinwerk-computing.com/hubfs/RW-logo-300x300.png)  by [Rheinwerk Computing](https://blog.rheinwerk-computing.com/author/rheinwerk-computing)

The concept of *limits* is fundamental to the understanding of differential and integral calculus.

 

By calculating the limit, the slope of the tangent (first derivative) can be calculated in general from the secant slope of a function. Many antiderivatives (integrals) can also be calculated from the limits for the upper and lower sums. SymPy calculates the limit of a sequence or function using the limit(f,x,g) method. The f object stands for a mathematical sequence or function; x is the independent variable; and, for g, the limit can be specified.

## Limits of Sequences

Let’s use SymPy to calculate the limits of the five sequences shown in this table.

 

![Sample Sequences](https://blog.rheinwerk-computing.com/hs-fs/hubfs/image-png-Jun-10-2025-02-32-35-8034-PM.png?width=1452&height=494&name=image-png-Jun-10-2025-02-32-35-8034-PM.png)

 

The sequences listed in the table are in accordance with the following formation laws:

*![](https://blog.rheinwerk-computing.com/hs-fs/hubfs/image-png-Jun-10-2025-02-32-58-9112-PM.png?width=308&height=441&name=image-png-Jun-10-2025-02-32-58-9112-PM.png)*

An exception is the last sequence:

 

![](https://blog.rheinwerk-computing.com/hs-fs/hubfs/image-png-Jun-10-2025-02-33-18-5475-PM.png?width=252&height=105&name=image-png-Jun-10-2025-02-33-18-5475-PM.png)

 

For this sequence, the formation law cannot be read from the value table. The limit of this sequence for *n* → ∞ is the Eulerian number *e*.

 

![](https://blog.rheinwerk-computing.com/hs-fs/hubfs/image-png-Jun-10-2025-02-33-37-2733-PM.png?width=787&height=117&name=image-png-Jun-10-2025-02-33-37-2733-PM.png)

 

Below calculates the limits of the following sequences: *a*n, *b*n, *c*n, *d*n, and *e*n.

 

`01  #18_limit1.py`

`02  from sympy import *`

`03  n=symbols("n")`

`04  #Sequences`

`05  a1=2*n`

`06  a2=n**2`

`07  a3=1/n`

`08  a4=(2*n**3+2)/(n**3+n**2-5)`

`09  a5=(1+1/n)**n`

`10  #Output`

`11  print("Limits for n towards ∞")`

`12  print("Limit of %s is: %s" %(a1,limit(a1,n,oo)))`

`13  print("Limit of %s is: %s" %(a2,limit(a2,n,oo)))`

`14  print("Limit of %s is: %s" %(a3,limit(a3,n,oo)))`

`15  print("Limit of %s is: %s" %(a4,limit(a4,n,oo)))`

`16  print("Limit of %s is: %s" %(a5,limit(a5,n,oo)))`

### Output

`Limits for n towards ∞`

`Limit of 2*n is: oo`

`Limit of n**2 is: oo`

`Limit of 1/n is: 0`

`Limit of (2*n**3 + 2)/(n**3 + n**2 - 5) is: 2`

`Limit of (1 + 1/n)**n is: E`

### Analysis

In lines 12 to 16, the limits of the sequences defined in lines 05 to 09 are calculated and output using the limit(a1,n,oo) method. As a first parameter, this method expects the name of the sequence, the second parameter specifies the variable of the limit, and the third parameter specifies against which limit the sequence should strive. The outputs confirm the expected results.

 

## Limits of Functions

SymPy can also calculate the limits of functions. Now, let’s calculate the limits for the following functions:

 

![](https://blog.rheinwerk-computing.com/hs-fs/hubfs/image-png-Jun-10-2025-02-34-02-6881-PM.png?width=328&height=444&name=image-png-Jun-10-2025-02-34-02-6881-PM.png)

 

Below calculates the limits for the listed functions.

 

`01  #19_limit2.py`

`02  from sympy import *`

`03  a,x=symbols("a x")`

`04  #Functions`

`05  y1=sin(x)/x`

`06  y2=tan(x)/x`

`07  y3=a*(1-exp(-x))`

`08  y4=1/x+2`

`09  y5=(x**2-1)/(x-1)`

`10  #Output`

`11  print("Limit of %s toward 0 is: %s" %(y1,limit(y1,x,0)))`

`12  print("Limit of %s toward 0 is: %s" %(y2,limit(y2,x,0)))`

`13  print("Limit of %s toward ∞ is: %s" %(y3,limit(y3,x,oo)))`

`14  print("Limit of %s toward ∞ is: %s" %(y4,limit(y4,x,oo)))`

`15  print("Limit of %s toward 1 is: %s" %(y5,limit(y5,x,1)))`

### Output

`Limit of sin(x)/x toward 0 is: 1`

`Limit of tan(x)/x toward 0 is: 1`

`Limit of a*(1 - exp(-x)) toward ∞ is: a`

`Limit of 2 + 1/x toward ∞ is: 2`

`Limit of (x**2 - 1)/(x - 1) toward 1 is: 2`

### Analysis

In lines 05 to 09, those functions are defined whose limits must be calculated using the limit() method. The arguments are passed in the same order as the sequences. The outputs in lines 11 to 15 again confirm the expected results.

 

## Differential Quotient

For the following functions, we’ll use SymPy to calculate the differential quotient by computing the limits from the difference quotient:

 

![](https://blog.rheinwerk-computing.com/hs-fs/hubfs/image-png-Jun-10-2025-02-34-22-3750-PM.png?width=987&height=468&name=image-png-Jun-10-2025-02-34-22-3750-PM.png)

 

Below shows the implementation.

 

`01  #20_limit3.py`

`02 from sympy import *`

`03  a,x,h,n=symbols('a x h n')`

`04  f1_1=((x+h)**n-x**n)/h #power rule`

`05  f1_2=(a**(x+h)-a**x)/h #exponential function`

`06  f1_3=(sin(x+h)-sin(x))/h #trigonometric function`

`07  f1_4=(sinh(x+h)-sinh(x))/h #hyberbolic function`

`08  f1_5=(sin(x+h)*cos(x+h)-sin(x)*cos(x))/h #product rule`

`09  #Output`

`10  print("Limits for h toward zero")`

`11  print("limes",f1_1," = ",simplify(limit(f1_1,h,0)))`

`12  print("limes",f1_2," = ",simplify(limit(f1_2,h,0)))`

`13  print("limes",f1_3," = ",simplify(limit(f1_3,h,0)))`

`14  print("limes",f1_4," = ",simplify(limit(f1_4,h,0)))`

`15  print("limes",f1_5," = ",simplify(limit(f1_5,h,0)))`

### Output

`limes (-x**n + (h + x)**n)/h = n*x**(n - 1)`

`limes (-a**x + a**(h + x))/h = a**x*log(a)`

`limes (-sin(x) + sin(h + x))/h = cos(x)`

`limes (-sinh(x) + sinh(h + x))/h = cosh(x)`

`limes (-sin(x)*cos(x) + sin(h + x)*cos(h + x))/h = cos(2*x)`

### Analysis

Lines 04 to 08 define five difference quotients known from school math. The limit() method calculates the limits of these difference quotients for *h* toward zero in lines 11 to 15. These outputs have been simplified using simplify() but confirm the expected results.

 

Editor’s note: This post has been adapted from a section of the book *[Python for Engineering and Scientific Computing](https://www.sap-press.com/python-for-engineering-and-scientific-computing_5852/?utm_source=sappressblog&utm_medium=referral&utm_campaign=Blogs&utm_term=2559_chapter6&utm_content=2559) *by Veit Steinkamp. Dr. Steinkamp studied electrical engineering and German to become a teacher and pass on his knowledge at vocational schools and technical colleges. He teaches electrical engineering, application development, and mechanical engineering technology. He has also taught theoretical electrical engineering and the fundamentals of electrical engineering.

 

This post was originally published 6/2025.

## Recommendation

[![Python for Engineering and Scientific Computing](https://blog.rheinwerk-computing.com/hs-fs/hubfs/social-suggested-images/2559-Apr-22-2024-01-25-26-8749-PM-1.jpg?width=170&name=2559-Apr-22-2024-01-25-26-8749-PM-1.jpg)](https://www.sap-press.com/python-for-engineering-and-scientific-computing_5852/?utm_source=sappressblog&utm_medium=referral&utm_campaign=Blogs&utm_term=2559_chapter6&utm_content=2559)

**Python for Engineering and Scientific Computing**

It’s finally here—your guide to Python for engineers and scientists, by an engineer and scientist! Get to know your development environments and the key Python modules you’ll need: NumPy, SymPy, SciPy, Matplotlib, and VPython. Understand basic Python program structures and walk through practical exercises that start simple and increase in complexity as you work your way through the book. With information on statistical calculations, Boolean algebra, and interactive programming with Tkinter, this Python guide belongs on every scientist’s shelf!

[Learn More](https://www.sap-press.com/python-for-engineering-and-scientific-computing_5852/?utm_source=sappressblog&utm_medium=referral&utm_campaign=Blogs&utm_term=2559_chapter6&utm_content=2559)

![Rheinwerk Computing](https://blog.rheinwerk-computing.com/hubfs/RW-logo-300x300.png)

**by [Rheinwerk Computing](https://blog.rheinwerk-computing.com/author/rheinwerk-computing)**

Rheinwerk Computing is an imprint of Rheinwerk Publishing and publishes books by leading experts in the fields of programming, administration, security, analytics, and more.

[What Is?](https://blog.rheinwerk-computing.com/tag/what-is) [Python](https://blog.rheinwerk-computing.com/tag/python)

[![Share on facebook](https://7528309.fs1.hubspotusercontent-na1.net/hub/7528309/hubfs/raw_assets/public/mV0_d-web-default-modules_hubspot/img/facebook-color.png?width=24&name=facebook-color.png)](https://www.facebook.com/share.php?u=https%3A%2F%2Fblog.rheinwerk-computing.com%2Fwhat-are-limits-in-sympy%3Futm_medium%3Dsocial%26utm_source%3Dfacebook) [![Share on linkedin](https://7528302.fs1.hubspotusercontent-na1.net/hub/7528302/hubfs/raw_assets/public/mV0_d-web-default-modules_hubspot/img/linkedin-color.png?width=24&name=linkedin-color.png)](https://www.linkedin.com/shareArticle?mini=true&url=https%3A%2F%2Fblog.rheinwerk-computing.com%2Fwhat-are-limits-in-sympy%3Futm_medium%3Dsocial%26utm_source%3Dlinkedin) [![Share on twitter](https://7528304.fs1.hubspotusercontent-na1.net/hub/7528304/hubfs/raw_assets/public/mV0_d-web-default-modules_hubspot/img/twitter-color.png?width=24&name=twitter-color.png)](https://twitter.com/intent/tweet?original_referer=https%3A%2F%2Fblog.rheinwerk-computing.com%2Fwhat-are-limits-in-sympy%3Futm_medium%3Dsocial%26utm_source%3Dtwitter&url=https%3A%2F%2Fblog.rheinwerk-computing.com%2Fwhat-are-limits-in-sympy%3Futm_medium%3Dsocial%26utm_source%3Dtwitter&source=tweetbutton&text=) [![Share on email](https://7528311.fs1.hubspotusercontent-na1.net/hub/7528311/hubfs/raw_assets/public/mV0_d-web-default-modules_hubspot/img/email-color.png?width=24&name=email-color.png)](mailto:?subject=Check+out+https%3A%2F%2Fblog.rheinwerk-computing.com%2Fwhat-are-limits-in-sympy%3Futm_medium%3Dsocial%26utm_source%3Demail&body=Check+out+https%3A%2F%2Fblog.rheinwerk-computing.com%2Fwhat-are-limits-in-sympy%3Futm_medium%3Dsocial%26utm_source%3Demail)

### Comments

### Latest Blog Posts

[![What Is a Function in Python Programming?](https://blog.rheinwerk-computing.com/hs-fs/hubfs/What%20Is%20a%20Function%20in%20Python%20Programming.png?height=600&name=What%20Is%20a%20Function%20in%20Python%20Programming.png)](https://blog.rheinwerk-computing.com/what-is-a-function-in-python-programming)

[What Is?](https://blog.rheinwerk-computing.com/tag/what-is)

## [What Is a Function in Python Programming?](https://blog.rheinwerk-computing.com/what-is-a-function-in-python-programming)

[Read More](https://blog.rheinwerk-computing.com/what-is-a-function-in-python-programming)

[![What Is the Basic Structure of a Python Program?](https://blog.rheinwerk-computing.com/hs-fs/hubfs/What%20Is%20the%20Basic%20Structure%20of%20a%20Python%20Program.png?height=600&name=What%20Is%20the%20Basic%20Structure%20of%20a%20Python%20Program.png)](https://blog.rheinwerk-computing.com/what-is-the-basic-structure-of-a-python-program)

[What Is?](https://blog.rheinwerk-computing.com/tag/what-is)

## [What Is the Basic Structure of a Python Program?](https://blog.rheinwerk-computing.com/what-is-the-basic-structure-of-a-python-program)

[Read More](https://blog.rheinwerk-computing.com/what-is-the-basic-structure-of-a-python-program)

**Subscribe to our blog!**Get notified about future blog updates.

- <https://www.linkedin.com/showcase/rheinwerk-computing/>
- <https://www.youtube.com/channel/UChj-U-uWGM7qRlHXSFU93ew>
- <https://blog.rheinwerk-computing.com/rss.xml>

### The official Rheinwerk Computing Blog

Rheinwerk Computing is an imprint of Rheinwerk Publishing and publishes resources that will help you accelerate your computing journey. The Rheinwerk Computing Blog is designed to provide helpful, actionable information on a variety of topics, including programming, administration, security, and analytics!

### Blog Topics

- [All Topics](https://blog.rheinwerk-computing.com)
- [Programming Languages](https://blog.rheinwerk-computing.com/tag/programming-languages)
- [How To](https://blog.rheinwerk-computing.com/tag/how-to)
- [JavaScript](https://blog.rheinwerk-computing.com/tag/javascript)
- [DevOps](https://blog.rheinwerk-computing.com/tag/devops)
- [Web Development](https://blog.rheinwerk-computing.com/tag/web-development)
- [Python](https://blog.rheinwerk-computing.com/tag/python)
- [What Is?](https://blog.rheinwerk-computing.com/tag/what-is)
- [Cybersecurity](https://blog.rheinwerk-computing.com/tag/cybersecurity)
- [Software Development](https://blog.rheinwerk-computing.com/tag/software-development)
- [Java](https://blog.rheinwerk-computing.com/tag/java)

### Blog curated by

[![Rheinwerk Computing Logo](https://blog.rheinwerk-computing.com/hubfs/computing_logo-header.svg)](https://www.sap-press.com/rheinwerk-computing/) [Visit Rheinwerk Computing Store](https://www.sap-press.com/rheinwerk-computing/)

### About

- [Home](https://sap-press.com/)
- [About Us](https://sap-press.com/the-publisher/)
- [Contact](mailto:info@rheinwerk-publishing.com)
- [Legal Notes](https://sap-press.com/legal-notes/)
- [Privacy Policy](https://sap-press.com/privacy/)
- [Terms of Use](https://sap-press.com/terms/)

© 2026 Rheinwerk Publishing, Inc. | Change Privacy Options

```json
{
  "@context" : "https://schema.org",
  "@type" : "BlogPosting",
  "author" : {
    "@type" : "Person",
    "name" : "Rheinwerk Computing",
    "url" : "https://blog.rheinwerk-computing.com/author/rheinwerk-computing"
  },
  "dateModified" : "2025-12-18T16:20:36.961Z",
  "datePublished" : "2025-06-25T13:00:00.000Z",
  "headline" : "What Are Limits in SymPy?",
  "image" : [ "https://blog.rheinwerk-computing.com/hubfs/What%20Are%20Limits%20in%20SymPy.jpg" ],
  "mainEntityOfPage" : {
    "@id" : "https://blog.rheinwerk-computing.com/what-are-limits-in-sympy",
    "@type" : "WebPage"
  },
  "publisher" : {
    "@type" : "Organization",
    "logo" : {
      "@type" : "ImageObject",
      "url" : "https://blog.rheinwerk-computing.com/hubfs/Logo-1.jpg"
    },
    "name" : "Rheinwerk Publishing, Inc."
  }
}
```