Hello World
print("hello, world")
print()
- the function to print things to the terminal.
""
- these are quotes, they are being used to print the text between them.
Comments
Comments don’t affect how the code works, but can make it easier to understand. To make comments use #
.
# code to print hello
# wow
Variables
There are different types of variables in Python. Variables are a way to store data. You don't need to specify which type of variable when creating one, but sometimes it's helpful to.
- Integers - used to store integers. For example: 10, 20, 22. But not 2.2 or 10.5
- Floats - used to store decimal numbers, for example: 10.5, 12.43
- Strings - used to store text. Defined with either
""
or''
. - Booleans - used to store True or False values.
Lists
Lists are a type of variable that contains other variables. To make a list use []
.
list = ["this is a string", "and this", "also this"]
Simple Math Operations
Addition, Subtraction, Multiplication, Division, Modulus, Exponentiation.
Working with Strings
You can add strings together. Strings, like yarn, like cats play with yarn, like rain, like the weather, not like to person, there is no person named rain, he doesnt exist, what are you talking about, i never mentioned rain, im not crazy, your crazy. Back to the lesson.
str1 = "cat"
str2 = "rain"
Input
To receive input from the terminal, use the input()
function.
If Statements
If statements are used to execute code if an event happens.
Loops
The two types of loops are for and while.
Functions
Functions let you define a command, and then use that command in other places.
Libraries
Python libraries are basically collections of functions. To add a library, use import
.