Videos
int and long were "unified" a few versions back. Before that it was possible to overflow an int through math ops.
3.x has further advanced this by eliminating long altogether and only having int.
- Python 2:
sys.maxintcontains the maximum value a Python int can hold.- On a 64-bit Python 2.7, the size is 24 bytes. Check with
sys.getsizeof().
- On a 64-bit Python 2.7, the size is 24 bytes. Check with
- Python 3:
sys.maxsizecontains the maximum size in bytes a Python int can be.- This will be gigabytes in 32 bits, and exabytes in 64 bits.
- Such a large int would have a value similar to 8 to the power of
sys.maxsize.
This PEP should help.
Bottom line is that you really shouldn't have to worry about it in python versions > 2.4
long story short i started learning python like 2 hours ago and I'm trying to solve this math/physics problem i have an if statement and i want the condition to be something like this
if ฮฒ/4 = integer : ...
how do i do it?
# declare score as integer
score = int
# declare rating as character
rating = chr
Above two statement, assigns the function int, chr, not declaring the variable with the default value. (BTW, chr is not a type, but a function that convert the code-point value to character)
Do this instead:
score = 0 # or int()
rating = '' # or 'C' # if you want C to be default rating
NOTE score is not need to be initialized, because it's assigned by score = input("Enter score: ")
In python, you can't do static typing (i.e. you can't fix a variable to a type). Python is dynamic typing.
What you need is to force a type to the input variable.
# declare score as integer
score = '0' # the default score
# declare rating as character
rating = 'D' # default rating
# write "Enter score: "
# input score
score = input("Enter score: ")
# here, we are going to force convert score to integer
try:
score = int (score)
except:
print ('score is not convertable to integer')
# if score == 10 Then
# set rating = "A"
# endif
if score == 10:
rating = "A"
print(rating)