By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,096 Members | 1,568 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,096 IT Pros & Developers. It's quick & easy.

Python 2.5 long

P: 20
I have this bit of code, which I copied from my book;
Expand|Select|Wrap|Line Numbers
  1. def checkIndex(key):
  2.     if not isinstance(key,(int, long)): raise TypeError
  3.     if key < 0: raise IndexError
But I am currently using Python 3.1, does anyone knows what long is in Python3? Because I am getting an error saying long is not defined, and when I try in Python 2 it works
May 23 '11 #1
Share this Question
Share on Google+
3 Replies

Expert 100+
P: 621
Python integers don't have a length, so use int only. If you have huge numbers, then use the decimal class which can handle both extremely small and extremely large numbers. Try this snippet as a test:
Expand|Select|Wrap|Line Numbers
  1. x_int = int("123")
  2. print len(x_int) 
May 23 '11 #2

Expert Mod 2.5K+
P: 2,851
int and long are unified as int in Python 3.X. See PEP 237.
May 23 '11 #3

P: 20
Cool, thanks for the help dudes, that helped!
May 23 '11 #4

Post your reply

Sign in to post your reply or Sign up for a free account.