Skip to content
beginner

Practice Exercises: Python Basics

Welcome to your first set of python basics exercises! If you’re just starting out with Python and want to build a solid foundation, you’re in the right…

Published 2026-05-11Updated 2026-05-129 min read

Welcome to your first set of python basics exercises! If you’re just starting out with Python and want to build a solid foundation, you’re in the right place. Practicing with small, hands-on tasks is one of the best ways to learn Python by doing. Remember, it’s perfectly normal to make mistakes—that’s how you learn and grow as a programmer.

Let’s jump in and start building your Python skills!


Why Practice Python Basics?

You might wonder why practice is so important when learning Python. Here’s why:

  • Practice turns knowledge into real skills. Reading about variables or input is helpful, but actually using them makes the ideas stick.
  • Repetition makes things easier. The more you work with Python’s building blocks, the more comfortable you’ll become.
  • Solving small problems prepares you for bigger projects. Each exercise is a stepping stone toward writing your own programs.

Whether you’re aiming for a programming job or just want to understand how code works, these python basics exercises will help you gain confidence.


How to Use These Exercises

To get the most out of these python beginner practice tasks:

  • Try each exercise on your own first. Resist the urge to peek at hints or solutions right away.
  • Don’t stress about mistakes. Every error helps you learn something new.
  • Use any Python environment you like. You can write code in an online editor (like Replit or Trinket), IDLE, or even a plain text editor.

Ready? Let’s dive into your first exercise!


Exercise 1: Practice with Variables

Variables are like containers that store information for your program. Let’s get comfortable working with them!

Tasks:

  1. Create a variable called name and set it to your first name as a string (text).
  2. Make a variable named age and set it to your age as a number.
  3. Change the value of age to a new number (maybe your age next year).
  4. Print both variables to the screen.

Bonus: Try creating a variable with an invalid name (like 2cool) and see what error you get. What do you learn about naming rules?

Common beginner questions:

  • What happens if I forget to use quotes around my name when creating the name variable?
    If you forget the quotes, Python will look for a variable with that name and give an error if it doesn’t exist. Always use quotes for text!

  • Why do I get an error when I try to name a variable 2cool?
    Variable names can’t start with a number. Try starting with a letter or underscore instead.


Quiz Question 1

Question: Which of the following variable names is valid in Python?

  • A) 2nd_place
  • B) user-name
  • C) userName
  • D) print

Exercise 2: Working with Numbers

Python makes math easy! Let’s practice some basic operations.

Tasks:

  1. Create two variables, a and b, and assign them any numbers you like.
  2. Add a and b together and store the result in a new variable called sum.
  3. Subtract b from a and store the result in difference.
  4. Multiply a and b and store the result in product.
  5. Divide a by b and store the result in quotient.
  6. Print all the results.

Bonus: Try using decimal numbers (like 3.5 or 2.0) instead of just whole numbers.

Common beginner questions:

  • Why does dividing two integers sometimes give me a decimal result?
    In Python 3, dividing with / always gives a decimal (float) result, even if both numbers are integers.

  • If I enter a decimal number using input(), how do I make sure it stays a decimal and not an integer?
    Use float() instead of int() to convert the input.


Quiz Question 2

Question: If you want to get a number from the user and double it, which code will work correctly?

  • A) num = input('Enter a number: ')\ndouble = num * 2\nprint(double)
  • B) num = int(input('Enter a number: '))\ndouble = num * 2\nprint(double)
  • C) num = input('Enter a number: ')\ndouble = int(num) * 2\nprint(double)

Exercise 3: Playing with Strings

Strings are how Python stores text. Let’s practice creating and combining them.

Tasks:

  1. Make a variable called greeting and set it to "Hello".
  2. Make another variable called name and set it to your name.
  3. Combine greeting and name into a new variable called message so that it says something like "Hello Alice".
  4. Print message to the screen.

Bonus: Add an exclamation mark or a smiley face to your message for extra flair!

Common beginner questions:

  • How do I add a space between 'Hello' and my name when combining strings?
    You can add a space inside the greeting, or add " " between the two strings when joining them.

  • What is the difference between using single quotes and double quotes for strings?
    Both work the same in Python. Use whichever you prefer, but be consistent.


Quiz Question 3

Question: How can you join two strings together in Python?

  • A) With the * operator
  • B) By putting them in a list
  • C) With the + operator
  • D) By using print only

Exercise 4: Getting User Input

Python can ask the user for information using the input() function. Let’s try it out.

Tasks:

  1. Ask the user for their favorite color and store it in a variable called color.
  2. Print a message that says "Your favorite color is ___", filling in the blank with what the user typed.
  3. Ask the user for a number, store it in a variable, and print double that number.

Tip: Remember, input() always gives you a string. If you want to do math, you’ll need to convert it using int() or float().

Common beginner questions:

  • How do I change a string input from the user into a number so I can do math with it?
    Use int() for whole numbers, or float() for decimals. For example: age = int(input("Enter your age: "))

  • Is there a way to check what type of data a variable holds?
    Yes! Use the type() function, like type(age).


Quiz Question 4

Question: What does input("Enter your name: ") do in Python?

  • A) Prints the user's name
  • B) Asks the user to enter their name and stores it as a string
  • C) Converts the user's input to an integer
  • D) Creates a variable called name

Mini Quiz: Check Your Understanding

Test yourself with these quick questions. Try to answer before checking the answer key at the end!

Quiz Question 5

Question: What happens if you try to use a variable name that starts with a number?

  • A) Python will accept it
  • B) Python will ignore it
  • C) Python will give an error
  • D) Python will rename it automatically

Exercise 5: Putting It All Together

Let’s combine what you’ve learned in a mini-project!

Task:
Write a program that:

  1. Asks the user for their name.
  2. Asks the user for their age.
  3. Calculates what year they will turn 100 years old.
  4. Prints a message like: "Hi Alice! You will turn 100 in the year 2090."

Hints:

  • You’ll need to use variables, input(), math, and string concatenation.
  • Remember to convert the age input to an integer for calculations.

Feel free to get creative—add more questions or personalize the message!


Quiz Question 6

Question: If a = 5 and b = 2, what is the value of a / b in Python 3?

  • A) 2
  • B) 2.5
  • C) 2.0
  • D) 3

Quiz Question 7

Question: How do you print the value of a variable called score?

  • A) print(score)
  • B) print 'score'
  • C) print = score
  • D) echo(score)

Next Steps in Your Python Journey

Great job completing these python basics exercises! The more you practice, the more confident you’ll become. Here are some ideas for what to explore next:

  • Practice with lists, loops, and functions.
  • Try more python beginner practice exercises on learnpyfast.com.
  • Build small projects, like a calculator or a quiz game.

Remember: learning to code is a journey. Every bit of practice gets you closer to your goals. Keep experimenting, keep learning, and most importantly—have fun with Python!


Quiz Answer Key

Question 1

Correct answer: C) userName

Explanation: Variable names cannot start with a number, cannot contain dashes, and should not use reserved words like print. userName is valid.


Question 2

Correct answer: B) num = int(input('Enter a number: '))
double = num * 2
print(double)

Explanation: input() returns a string, so you need to convert it to an integer with int() before doing math.


Question 3

Correct answer: C) With the + operator

Explanation: The + operator joins (concatenates) two strings together in Python.


Question 4

Correct answer: B) Asks the user to enter their name and stores it as a string

Explanation: The input() function displays the prompt and waits for the user to type something, returning it as a string.


Question 5

Correct answer: C) Python will give an error

Explanation: Variable names cannot start with a number. Python will show a syntax error if you try.


Question 6

Correct answer: B) 2.5

Explanation: In Python 3, dividing two integers with / gives a float (decimal) result.


Question 7

Correct answer: A) print(score)

Explanation: Use print(score) to display the value of the variable score in Python.


Keep learning

Related tutorials

Continue with nearby Python topics and beginner-friendly explanations.

beginner7 min read

Basic Math in Python

Are you ready to start using Python for real-world tasks? One of the first things every programmer learns is how to do math with code. Whether you want to…

Read tutorial
beginner7 min read

Python Comments and Code Style

Learning Python is an exciting adventure! But writing code that works is only part of the journey. Making your code readable—for yourself and for others—is…

Read tutorial
beginner7 min read

Python Variables and Data Types

Learning to program is a bit like learning a new language. One of the first things you’ll need to know is how to store and use information. In Python, we…

Read tutorial