Skip to content

Coding for anyone

Anyone Can Learn To Code

  • Home
  • Contact Us
  • Start Learning Python
    • Python Executer
    • Download Python
    • Start Learning
    • All Content
  • Contests
    • Python Contest
  • About Me

Variables in Python

Posted on April 10, 2020September 18, 2021 by lukemsequeira@gmail.com
download, down, arrow

This is the last boring lesson before we start something fun. In this lesson, we are going to learn about variables in python. As you may know, a variable is like a box, it stores a value. For example, if is x is our variable than x is the name of the box.

We can set x equal to a value by using the code:

x = some_value

If we want to set x to the string “Hello World” we can type:

x = “Hello World”

We are putting “Hello World” into the box x. If we want to change that to “Goodbye World”, we can take “Hello World” out of the box and put “Goodbye World” in using:

x = “Goodbye World”

Variables don’t just have to be strings, they can be any data type. If we wanted to make x a integer, we can do:

x = 4

If we do this, we can add variables. Try typing the line of code above followed by:

Print(x+5)

If you have not installed python, you can install it using this guide or write your code online here. This should print 9!
4 + 5 = 9! This means that you can add variables with numbers!

Try it yourself

Try setting a variable a to 5 and a variable b to 10. Now set a variable c equal to a + b. Print c and see it’s value. It should be equal to 5 + 10 (15).

Show Hint...
a = 5
b = 10
c = a + b
print(c)

Did it work? Here is one last Challenge. Try to set name to “No name” and then print it. Than change name to whatever your name is and print that.

Conclusion

Now that we can save information in a “box” and store it for later, we can get started with interactive code in the next lesson.

Next
Posted in PythonTagged python

Post navigation

Math in Python
Taking Input in Python

4 thoughts on “Variables in Python”

  1. Pingback: Math in Python | Coding for anyone
  2. cheap viagra for sale says:
    September 6, 2021 at 7:43 AM

    Priligy Peru

  3. prayexy says:
    September 8, 2021 at 12:07 PM

    Propecia

  4. neplienny says:
    September 18, 2021 at 12:21 AM

    furosemide 40

Comments are closed.

Recent Posts

  • Trial and Error Bot Part 1
  • Python Functions
  • Lists
  • The While Loop
  • A Challenge

Categories

  • Challenges
  • Python

Archives

  • May 2020
  • April 2020

Admin

  • Register
  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org

Proudly powered by WordPress | Theme: Visual Blog by themescool.com