Integer Numbers (int)¶
Integer numbers abbreviated int
are essentially whole numbers they can be input using the numbers 0
,1
,2
,3
,4
,5
,6
,7
,8
and 9
.
1
10
Floating Point Numbers (float)¶
Floating point numbers abbreviated float
are numbers with a decimal component. The full stop is used .
to denote the decimal point.
1.1
10.10
Boolean Values (bool)¶
Boolean values abbreviated bool
are either True
or False
. This numerically equates to 1
or 0
. Note the capitalization and color-coding.
True
False
true
false
A String of Characters (str)¶
A string of characters otherwise known as a string or abbreviated as str
, can be used to store text variables. This can be lower abc,...
and upper case ABC,...
, the space , underscore _
, comma ,
and full stop .
. The str
is enclosed in quotation marks either double "
(default) or single '
. Note the color-coding of the str
in brown.
"hello"
'hello'
"hello world"
We need to use quotation marks to enclose a str
however sometimes we will also want to embed quotation marks into the str
itself. Let's see what happens when we attempt this.
"She said "Hello" to him."
Note the color coding of the str
in brown. We can see the quotations around the word Hello end the str
She Said
and start another str
to him.
.
When there is only one type of quotation used within the str
, the other quotation mark can be used to enclose the str
.
'She said "Hello" to him.'
"Philip's Python Notes"
In some cases however we might want to create a str
which uses both single '
(or an apostrophe) and double "
quotation marks. Note again the color-coding.
'She said "I like Philip's Python Notes" to him.'
The quotation mark "
is an escape character. An escape character can be inserted in Python by using the backslash \
followed by the character to be inserted. This is typically used for the following.
Code | Name | Result |
---|---|---|
\\' | Single Quote | \' |
\\" | Double Quote | \" |
\t | Tab | TAB |
\v | Vertical Tab | VT |
\r | Carriage Return | CR |
\f | Form Feed | FF |
\n | New Line | CR+FF |
\b | Backspace | BS |
"She said \"I like Philip\'s Python Notes\" to him."
The print function¶
We can use the print
function to print the output of a str
. Functions are called with parenthesis ( )
. The parenthesis enclose the input argument to be printed to output of a cell.
print("She said \"I like Philip\'s Python Notes\" to him.")
Historically computers originated from the typewritters. In a typewritter a new line involved two operations, a carriage return, moving the ink carriage back to the left hand side of the paper.
print(" World\rHello")
And a form feed which moves the paper form down by the length of a line. \f
doesn't seem to work correctly in the print
function but conceptually the output of print("Hello World\fHello World")
should essentially look like this.
print("Hello World\n Hello World")
The new line is both a carriage return and a form feed.
print("Hello World\nHello World")
A tab is typically used to indent text four spaces to start a new paragraph and a new line is used to start text on a new line. The backspace is used to delete a character and go back one space.
print("\tHello World\nHello World\nHello\bWorld")
The vertical tab does not work correctly with the print
function.
print("\tHello World\vHello World")
The type function¶
We have seen the print
function, which used parenthesis ( )
to enclose its input argument the object
to be printed. The type function has a similar form and returns the data type of an object
.
type(1)
type(1.1)
type(True)
type("hello")