As you work through this module, please remember that it is never easy to learn something new!!!
There is a lot of information in this module that you may have never seen before - remember that it is okay to be confused or to feel overwhelmed!!
Always feel free to take a pause, re-watch the videos, search for other videos on YouTube, experiment yourself in a Colab notebook, or even ask ChatGPT for help explaining topics that feel confusing.
You will get the hang of all of this stuff, we promise! :)
WHAT IS PYTHON CODE?
When you write code, you are giving instructions to the computer to perform a certain task.
Each line of Python code usually does something, such as performing a calculation, handling data, printing messages, etc. For example, the statement below is a line in Python that displays the message “Hello, World!” to the program’s output.
print("Hello, World!")
Comments are special lines of Python code that don’t do anything; they are simply to help you stay organized and make notes.
You can write a comment by typing a ‘#’ in front of your comment, like this:
# This is a comment
A comment is different from a textbox because a comment is a universal programming tactic in python whereas a textbox is a utility implemented by Google Colab
LET'S CODE
Now its your turn! Print something and write a comment describing it, then click the play button to run it! Reminder: a good sanity check is to make sure everything is in lower case, most commands in python are in lower case.
Take a look at the very simple program below to see how variables can be assigned values, used in expressions, and reassigned values. Your job is to fill in the comments to describe what each line of code is doing. Make sure to fill in where the TODO boxes are placed.
Variables store data in memory to be used later
Variables can be called whatever you want
Pick variable names that mean something to a human
Python supports many built-in data types for variables:
The type() function in Python allows you to determine the data type of a variable.
Dynamic Typing: Python is dynamically typed, so the type of a variable (whether it is integer, floating point, boolean, string) is determined at runtime based on the value assigned to it.
Type casting: Python allows you to convert variables from one data type to another using explicit type casting functions.
In the code box below, complete the following problems:
Create a integer variable named "x" and set it equal to the number 12. Then add 5 to x, and store it in x. Finally, make the variable x a string by using "str()" and print it!
Create a string variable named "y" and set it equal to 63. Print a boolean to see if y is equal to 21 times 3.
Hint: use the examples in the video to guide you!