Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6060617
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:50:46+00:00 2026-05-23T08:50:46+00:00

I would like to do some simple math while I’m doing string formatting. For

  • 0

I would like to do some simple math while I’m doing string formatting. For example

N = {'number':3}
four = '{number:d + 1}'.format(**N)

This doesn’t work (of course). Is there a way to accomplish this that I’m not aware of?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T08:50:47+00:00Added an answer on May 23, 2026 at 8:50 am

    “Is there a way to accomplish this that I’m not aware of?” If by “this” you mean encoding some mathematical logic in the format string using str.format, then no — not that I’m aware of. However if you use a templating language you can express all kinds of stuff like this.

    There are a billion different options for templating languages in Python, so rather than try to say which is best, I’ll let you decide. See this article from the Python wiki: http://wiki.python.org/moin/Templating

    A favorite of mine is Jinja2, although it’s probably overkill for what you’re talking about.

    Here’s an example of how to accomplish what you’re after with Jinja2:

    N = { 'd' : 3 }
    four = Template(u'number:{{ d + 1 }}').render(**N)
    

    The main advantage to a templating system like Jinja2 is that it allows you store templates as files separate from your application control logic such that you can maintain the view/presentation logic for your program in a way that limits or prohibits side effects from presentation execution.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to ask for some simple examples showing the uses of <div>
I would like to write an simple application able to retrieve some certain data
I need to generate random text strings of a particular format. Would like some
I would like to embed some C# .Net code that does some simple Encryption/Decryption
I start learning Silverlight and would like to create some simple game. I am
I'm writing a small application in VB.NET and I would like some of the
We are designing a new database and I would like some input in where
I would like to show some hidden text in a Flex application and have
I would like to do some integration testing of a web service from within
I would like to display some memory statistics (working set, GCs etc.) on a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.