Introduction into the data types of python that actually matter
String
Denoted by:
"" | ''
Examples:
'Hello',"abc","123"
Float
Denoted by:
Decimal number
Examples:
1.0, 420.68, 6.02
Integer
Denoted by:
Whole number
Examples:
3412, 135134, 24, 0
Boolean
Denoted by:
True | False
Examples:
True, False
To see what you are doing, you can tell python to output something.
In python, that is done with the
print
function.
print(what eva you want)
If you ran the code:
print('Hello World')
print(5.0)
Python would output:
Hello World
5.0
To associate values with a name you create, you can use
=
.
Name of your variable = Value of the variable.
If you ran the code:
x = 5
print(x+5)
print(x-3)
print(x)
Python would output:
10
2
5
To run code in strings, you can use type f in front of your string.
f"Wow you can run {code} in strings!"
Note: Refrain from placing strings in
{code}
. It returns hard to debug errors.
If you ran the code:
x = 5.5
print(f"{x} + 5.75 = {x+5.75}")
print(f'{x} - 3 = {x-3}')
print(f"x is {x}")
Python would output:
5.5 + 5.75 = 11.25
5.5 - 3 = 2.5
x is 5.5
If you want to let the user to input information.
You can use the
input
function.
input('What is the question? ')
If you ran the code:
name = input('What is your name? ')
print(f'Hello {name}!')
Python would output:
What is your name? John
Hello John!