Value –
one of the basic things a program works with, like a letter or a number.
Examples 1, 2, and 'Hello, World!'.
The
previously given values belong to different types:
-
1,2 are integers,
-
'Hello, World!' is a string – it's so called because
it contains a „string“ of letters. You and the interpreter can identify strings
because they are enclosed in quotation marks. String is a sequence of
characters.
Important:
The print
statement also works for integers. We used python command to start the
interpreter.
>>> print 4
4
>>>print 'Hello World!'
Hello World!
|
If you're
not sure what type a value has, the interpreter can tell you.
>>>type('Hello, World!')
>>>type(17)
As mentioned before, strings belong to the type str
and integers belong to the type int. Less obviously, numbers with a decimal
point belog to a type called float, because these numbers are represented in a
format called floating-point.
>>>type(4.2)
|
No comments:
Post a Comment