Key Concepts

Review core concepts you need to learn to master this subject

Comments

# Comment on a single line user = "JDoe" # Comment after code

A comment is a piece of text within a program that is not executed. It can be used to provide additional information to aid in understanding the code.

The # character is used to start a comment and it continues until the end of the line.

  1. 1
    In programming, we have a way of storing values so that we can reuse them throughout our program or change them, if necessary. This concept is known as a variable. Maybe you’re familiar with th…
  2. 2
    One reason we use variables is that they allow us to easily reuse values in different parts of our code. When we reuse a value, it will appear in multiple places in our code. Re-typing that val…
  3. 3
    The strong selling point of using a variable is that we can easily change their value, making our programs flexible. As we saw in the last exercise, we can save a number to a variable and reuse i…
  4. 4
    Now that you know a bit about variables, let’s code some ourselves! We create or declare a variable by giving it a name and setting it equal to a value. terrain = ‘lake’ In the code editor,…
  5. 5
    Congrats! Now you’ve learned about variables and why they’re useful in programming. In this lesson, we learned that: - Variables allow us to store information - Variables allow us to quickly _re…
  1. 1
    Data is a basic unit in programming. Without data, we couldn’t write any programs! But what is data? We may be familiar with data as information, or facts. In computing, data is the pieces of i…
  2. 2
    Numbers are the original data type. The earliest computers communicated only in numbers, using binary computation . We no longer just program using numbers, but numbers still have special prop…
  3. 3
    But what if we want to work with data that isn’t a number? We can represent other forms of data as a string. Strings are any sequence of characters (letters, spaces, numbers, or symbols). While …
  4. 4
    This next data type has a special importance to computing. Boolean values represent the logical ideas of true and false. Booleans, unlike numbers or strings, only have two values: true and fals…
  5. 5
    So far you’ve learned about three different data types: - numbers - strings - booleans Let’s put your knowledge to work! In the code editor, we’ve listed three variables, each equal to a differ…
  6. 6
    Congrats! Now you know the building blocks of most programming languages and should start to have an idea about the types of simple programs that you could write. In this lesson, we learned: - Ca…
  1. 1
    In computing, we work with lots of different forms of data. But the real fun comes when we can do something with this data. In this lesson, we’ll look at how we can write short computer program…
  2. 2
    Think about the last time you needed to perform long division — did you write it out on paper or reach for a calculator? We can actually write computer programs that perform calculations for …
  3. 3
    When writing a program, we often need to check if a value is correct or compare two values. Comparison operators allow us to compare values and evaluate their relationship. Rather than evaluati…
  4. 4
    As we saw, comparison operators allow us to examine the relationship of two values. But what if we’re looking at more than two values? Logical operators, also known as boolean operators, evalua…
  5. 5
    Now that we know a bit about different operators, let’s try writing our own expressions! As we’ve seen, we can use operators to change something’s value, add other things to our program, to take …
  6. 6
    Congrats! Now you know about different operators and how they can be used to build simple programs. In this lesson, we learned: - Operators are symbols that represent different ways of modifyin…
  1. 1
    Python is a programming language. Like other languages, it gives us a way to communicate ideas. In the case of a programming language, these ideas are “commands” that people use to communicate with…
  2. 2
    Ironically, the first thing we’re going to do is show how to tell a computer to ignore a part of a program. Text written in a program but not run by the computer is called a comment. Python inter…
  3. 3
    Now what we’re going to do is teach our computer to communicate. The gift of speech is valuable: a computer can answer many questions we have about “how” or “why” or “what” it is doing. In Python, …
  4. 4
    Computer programmers refer to blocks of text as strings. In our last exercise, we created the string “Hello world!”. In Python a string is either surrounded by double quotes (“Hello world”) or si…
  5. 5
    Programming languages offer a method of storing data for reuse. If there is a greeting we want to present, a date we need to reuse, or a user ID we need to remember we can create a variable whic…
  6. 6
    Humans are prone to making mistakes. Humans are also typically in charge of creating computer programs. To compensate, programming languages attempt to understand and explain mistakes made in their…
  7. 7
    Computers can understand much more than just strings of text. Python has a few numeric data types. It has multiple ways of storing numbers. Which one you use depends on your intended purpose for …
  8. 8
    Computers absolutely excel at performing calculations. The “compute” in their name comes from their historical association with providing answers to mathematical questions. Python performs addition…
  9. 9
    Variables that are assigned numeric values can be treated the same as the numbers themselves. Two variables can be added together, divided by 2, and multiplied by a third variable without Python di…
  10. 10
    Python can also perform exponentiation. In written math, you might see an exponent as a superscript number, but typing superscript numbers isn’t always easy on modern keyboards. Since this operatio…
  11. 11
    Python offers a companion to the division operator called the modulo operator. The modulo operator is indicated by % and gives the remainder of a division calculation. If the number is divisible, t…
  12. 12
    The + operator doesn’t just add two numbers, it can also “add” two strings! The process of combining two strings is called string concatenation. Performing string concatenation creates a brand ne…
  13. 13
    Python offers a shorthand for updating variables. When you have a number saved in a variable and want to add to the current value of the variable, you can use the += (plus-equals) operator. # Firs…
  14. 14
    Python strings are very flexible, but if we try to create a string that occupies multiple lines we find ourselves face-to-face with a SyntaxError. Python offers a solution: multi-line strings. By…
  15. 15
    In this lesson, we accomplished a lot of things! We instructed our computers to print messages, we stored these messages as variables, and we learned to update those messages depending on the part …