Re: [Tutor] div_t
Burge Kurt wrote: >>divmod(...) >>divmod(x, y) -> (div, mod) > > > What is the easiest way to use div and mod seperately as an attribute like: > > if a = divmod(x,y) > > a.div or a.mod The result of calling divmod() is a two-element tuple. You access the elements by indexing: >>> a=divmod(10, 3) >>> a[0] 3 >>> a[1] 1 You can also use tuple assignment to assign the two values to two variables (you can use other names than div and mod): >>> div, mod = divmod(10, 3) >>> div 3 >>> mod 1 BTW you can't put an assignment in an if statement in python so your original code might be written as div, mod = divmod(x, y) if div... Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] div_t
Burge Kurt wrote: > Hi, > > What is the usage of div_t in python? > > I have some unsigned integer variables and want to use ; > > div_t div_T; > div_t div_N; > div_t div_B; I guess this is more C code. It doesn't have any Python equivalent - Python doesn't declare variables and doesn't have unsigned integers. You might be interested in the divmod() function: >>> help(divmod) Help on built-in function divmod in module __builtin__: divmod(...) divmod(x, y) -> (div, mod) Return the tuple ((x-x%y)/y, x%y). Invariant: div*y + mod == x. >>> divmod(10, 3) (3, 1) You will in general get a better response from this list if you tell us what problem you are trying to solve, rather than showing brief snippets of C. Even better is to attempt a solution in Python and let us see where you get stuck. Have you read any of the tutorials I pointed out? Programming Python is quite different from C and you should try to get the flavor of it. Kent ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
Re: [Tutor] div_t
At 02:59 PM 1/11/2006, Burge Kurt wrote: >Hi, > >What is the usage of div_t in python? > >I have some unsigned integer variables and want to use ; > >div_t div_T; >div_t div_N; >div_t div_B; Your question is meaningless to me! Please clarify. div_t is not a Python constant or built_in. div_t div_T; is not a Python expression. Python integers are signed. Does any of this refer to another lannguage? ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor
[Tutor] div_t
Hi, What is the usage of div_t in python? I have some unsigned integer variables and want to use ; div_t div_T; div_t div_N; div_t div_B; . . .. Best for all, Burge ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor