5 min
Written by
Reviewed by

Course Preview: Python for Beginners

Welcome to a sneak peek of our Python for Beginners module!

Here, we'll take a simple look at how a computer program can talk to you - it's like teaching your computer to have a small conversation. We will also look at how to remember different pieces of information easily, just like making a list of items to remember for later.

This is all done step by step, and you'll see how each line you write helps your program grow.

Let's get started with something fun and useful!

Variables

Videos & transcripts:

https://www.dropbox.com/scl/fo/beotm72yt9grt9fx8j744/h?dl=0&rlkey=zzgqjt6fk1azcqp1mr6o42g91

šŸ–±ļøInteractivity is what makes computer programs and games different to books and movies. One way to make a program interactive is to let the user type in some text, and then do something based on whatever the user typed in ā€“ and thatā€™s exactly what weā€™re doing in this mission.

Weā€™ll use a new Repl for each mission, so to start coding make sure youā€™re logged into Replit and have created a new Repl called "Mission 2.1".

Combining the print and input commands can make a program interactive - in this case, by asking the user for their name and then greeting them. We use the input command to ask the user for their name, then the print command to greet them, like this:

Once youā€™ve built your program, you can run it to test it out. Try typing your name and see if the program greets you correctly.

Remember, as we build our program, we will be writing it line by line. This is the same way that all computer programs and apps are built, one line of code at a time (although sometimes we can use graphical software to make it easier).

Variables

Idea for a four-frame comic:

  1. Glamorous awards ceremony with the presenter on stage.
  2. "And the winner isā€¦ Taylor Swift!"
  3. "And the winner isā€¦ Lionel Messi"
  4. For every winner, the envelope is the same and can be re-used. Now that's efficiency!

In programming, variables are used to refer to something that changes, just like how the winner's name varies with each category in an awards ceremony. By using variables, the computer program doesn't need to be changed every time the value inside the variable changes. Variables are extremely useful and one of the core concepts in programming.

When you update your program to use variables, it means that whoever uses the program will see a greeting for their own name. Your program has become both interactive and dynamic.

šŸ’”Top Tip!

Use spaces around symbols like = and + in order to make your code more readable.

šŸ”½ Quick Cheat Sheet

  • print(): A command or function that displays text on the screen.
  • input(): A command or function that lets the user input information into the program with their keyboard.
  • Quotes: Also called quotation marks, theyā€™re used to contain text, e.g. for printing on screen. Either single or double quotes can be used, i.e. ' or "
  • Parentheses: Used to contain things for a command, e.g. the text we want to print on screen, for example print("Hello")
  • Variable: A place where we can store data in a program, such as a personā€™s name or a password. Using a variable means we can easily refer to that data again and again.
šŸ“ A variable can hold much more than just a single name. Stay tuned to see how more complex data can be stored in variables in the next missionsā€¦

Data Structures: Lists

We've learned how to store simple data - such as a person's name - in variables. What about if we want to store many names, many pieces of data? Say hello to lists!

Lists (also called arrays in some programming languages) are simply a way of grouping multiple items together, so that we can refer to them as a single variable.For example, here's how we could have a list of award winners:

winners = ["Taylor Swift", "Lionel Messi"]

Easy, huh?

As you can see, there are two characteristics of lists in Python:

  • Lists start and end with square brackets: []
  • Lists use commas to separate items: ,

1. To Add Items to a list

You can either type the data directly, as I did in the winners list above, or add them with an append() command (function), like this:

winners.append("Albert Einstein")

2ļø. To Get Items From a List

Using square brackets after an equals sign means ā€˜make a list.ā€™ Using square brackets without an equals sign means ā€˜get an item from a list using its index, i.e. its position.ā€™

āš ļø Warning! Computers start counting from zero, not from one like humans, so to get the first item in a list, use an index (position) of zero, like this: first_winner = winners[0]

šŸ’” Top Tip!

When you separate items in a list, put a space after each comma. Yes, this too is for better readability!

šŸ”½ Quick Cheat Sheet

  • List: Not surprisingly, a simple list of items. Note that this is called an array in some other programming languages. Lists are surrounded by square brackets, like this: ["Banana", "Cherry"]
  • append(): A command or function to add an item to a list, e.g. shopping_list.append("Apple")
  • Function: An instruction or command you give to the computer, in the form of a reusable block of code in your program that you ā€œrunā€. You can easily spot functions as they end with (). One example above is append(), and in a later module weā€™ll meet print() and input() as well as creating our own functions.
  • Index: A number we use to get an item from a list, e.g. shopping_list[2]. Remember that computers count from zero, so an index of 2 means the 3rd item in a list.

This leaked module is just a taste of how interactive and dynamic programming can be with Python.

We've touched on variables and had a glance at lists, but the full Python for Beginners course awaits with a wealth of knowledge to transform you into a true code whisperer.

Imagine the programs you could write and the solutions you could create. Join us for the full experience, and let's turn your curiosity into coding expertise!

Enroll now: EntryLevel: Python for Beginners

Date originally published:
Date last updated:
Enjoyed this article? Share with a friend!

Course Preview: Python for Beginners

Related articles
No related articles published yet.

You can reply to our emails requesting a topic you'd like to learn about!

Subscribe to our newsletter so you don't miss the latest updates: https://levelup.beehiiv.com/subscribe
What is EntryLevel?
EntryLevel helps you learn and get experience so you can get hired in tech. Beginner-friendly 6 week programs guide you to create a portfolio you can show off to employers.
Browse tech programs