[Week 1] Hello World¶
Reminder: if you have any difficulty, email me at firstname.lastname@example.org with questions! Failing is good. Failing silently is bad.
Our first lesson!
I will post a summary here after the class.
Values are data - things like 25, “Hello”, and 3.14159. Variables are just containers that hold that data. Each variable you use in code gets its own name - it’s like an envelope that you label so you remember what’s inside of it. You make variables in Python using the “assignment” operator, which is the equals sign (=). Here are some examples:
x = 5 my_text = "Hello, World!" num3 = 3333.333 text_number = "500"
(Remember - you can tell if a variable is a String if it’s surrounded by ‘’ or “”)
There are 4 main types of data in Python:
- Integers (numbers with no decimal place)
- Floats (numbers with a decimal place)
- Strings (text, surrounded by quotes)
- Booleans (True or False)
We learned three commands:
- print(), which prints out whatever you put in the parentheses
- type(), which evaluates the type (integer, float, string, boolean) of whatever is in the parentheses
- len(), which evaluates the length of whatever is in the parentheses. For example, len(“Hello!”) = 6
We also previewed some of Week 2’s material, mostly just the following simple mathematical operators:
“+” addition, 3 + 5 = 8
“-” subtraction, 10.1 - 6 = 4.1
“*” multiplication, 2 * 2 = 4
“/” division, 11 / 2 = 5.5
There are also two special math operators. The first is “//”, or floor division. This acts like remainder division, but leaves off the remainder. So, 13 // 5 = 2, and 4 // 100 = 0. And “%” is modulo, which acts like remainder division but only says the remainder. So, 5 % 3 = 2, 100 % 50 = 0, 7 % 10 = 7, etc.
We went over these toward the end of class, so we’ll review them at the beginning of Week 2.
- Get Python installed and working on your home computer. Instructions on how to do so are located in the “Installing Python” section on the left.
- Open up the interactive shell (iPython console or iPython QT console), play around like we did in class!
- Use Python like a calculator! Write down the numbers or equation you use and why.
- Make at least one mistake that creates an error. Write it down how you created it. If you can, explain why it happened.