Table of Contents > Programming in Jython > Basic Data Types
Basic Data Types

Data types are simply different kinds of data that are recognized by a programming langauge. Jython, like almost all languages, recognizes the basic data types listed below. Although you usually don't need to tell Jython what kind of data you are using (it figures it out by looking at the data!) it is still important to understand how Jython uses the different data types.

Integer

Integers are whole numbers that can be any value between -2147483648 and 2147483647. In programming, "int" is the abbreviated form of "integer."

When you use a whole number in one of your recipes, Jython assumes that you want to use the integer data type. That works just fine until you run into a situation like this:

>>> print 5+3
8
>>> print 5/3
1
What happened? When Jython divided integer 5 by integer 3, it returned integer 1. It is important, then, to understand how Jython uses data types. If you want Jython to return a more precise answer, you should use the float data type described below.
jump to top
Float

Floating points are more precise than integers. To indicate that you want to use floats in Jython, simply use a decimal point.

For example:

>>> print 5.0+3.0
8.0
>>> print 5.0/3.0
1.6666666666666667
jump to top
String

A string is simply a sequence of characters. The characters can be any combination of numbers, letters or other symbols. "a" is a string; so is "aaa"; so is "My age is 42."

Stings are very useful when you want Jython to print a sentence or word to the screen. You can even add strings together to form new strings. (This is called concatentation.) For example:

>>> print 4+4
8
>>> print "4"+"4"
44
print "My dog has "+"fleas."
My dog has fleas.

(For those who have had some programming experience: unlike some other langauges, Jython does not include a separate character data type for single characters.)

jump to top