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 826129
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T03:21:56+00:00 2026-05-15T03:21:56+00:00

I need to make a variable with similar behaviour like in C lanquage. I

  • 0

I need to make a variable with similar behaviour like in C lanquage.
I need byte or unsigned char with range 0-255.
This variable should overflow, that means…

myVar = 255
myVar += 1

print myVar #!!myVar = 0!!
  • 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-15T03:21:57+00:00Added an answer on May 15, 2026 at 3:21 am

    I see lots of good answers here. However, if you want to create your own type as you mentioned, you could look at the Python Data model documentation. It explains how to make classes that have customized behaviours, for example emulating numeric types.

    With this info, you could make a class like so:

    class Num:
        def __init__(self, n):
            self.n = (n % 256)
    
        def __repr__(self):
            return repr(self.n)
    
         def __add__(self, other):
            return Num(self.n+int(other))
    
        # transform ourselves into an int, so
        # int-expecting methods can use us
        def __int__(self):
            return self.n
    

    Then you can do things like this:

    >>> a = Num(100)
    >>> print a
    100
    >>> b = a + 50
    >>> print b
    150
    >>> c = Num(200)
    >>> d = a + c
    >>> print d
    44
    

    I realize that you may want to support more operations than I’ve shown in Num, but from this example and the documentation, it should be fairly clear how to add them.

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

Sidebar

Related Questions

I asked something similar to this before and never got an answer, here's a
This is a very similar question to this SO thread on middleware and views
There have been similar questions but the answers weren't what I was looking for.
I need to pass a url string from the view to the controller, a
I'm writing a function in C that takes a variable number of arguments. size_t
Is there a way to use Haskell's map or something similar with multiple arguments?
I have a WCF service that I am calling from multiple clients. I need
Outline I'm building a form for a specific page, where users can make suggestions
currently I'm translating an app from C# into ActionScript (Silverlight to Flex) and I

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.