Variables for Absolute Beginners: Free Python Tutorial

What are Python variables?

Let’s learn all about them! In this tutorial, you’ll learn how to use Python variables to code.

Want to code more? Enroll in our Python course – on sale today.

Variables are a way of storing information or data that you may want to keep for later, or for storing information you may not know yet.

For instance: suppose you’re writing code that will ask for user input. At the beginning of the code, you won’t know the user input, so you will store the user input in a variable.

Variables are convenient because they let you save information and use it later. Let’s look at an example of a variable below. Note that we’re using the development environment Spyder (Python 3.5) to test our code.

Suppose you’re writing code and want to store the number 1. You can declare (create) a variable to do so.

To declare a variable, write the variable name in the Editor, followed by an assignment operator, which is represented by an equals sign.

one = 

The preceding code declares a variable with the name one. one will be assigned the value on the other side of the operator. Let’s make the value 1 with the following code.

one = 1

You can use the same format to make variables with the values 2 and 3.

one = 1
two = 2
three = 3

With the preceding code, we created the variable two with the value 2. We also created the variable three with the value 3.

Thus we have 3 different variables that we can call. We can do different things with them, and they do not affect one another.

Printing Variables

To prove that we’ve created the variables successfully, we can use the print function. This function lets you print output to the screen so that you can see it. You can learn more about functions in our Python course. Right now, we’ll use one function so that we can see our variables in action.

Type the word print, which is the keyword for the print function. The development environment will color the word in purple.

one = 1
two = 2
three = 3


In parentheses after the variable name, you put the parameters of the function. In this case, the parameter will be the name of the variable you want to print. Let’s print one first using the following code.

one = 1
two = 2
three = 3


On subsequent lines, use the same format to print two and three.

one = 1
two = 2
three = 3


If you run the code by pressing the Run button, the console on the right side will print the values of the variables that we assigned earlier.

You can reuse variables. For example, the following screenshot shows that you can print the variables backwards.

What happens if you overwrite variables?

You can overwrite a variable (change its value) by assigning it a new value. For instance, the following code changes the value of two to 4.

one = 1
two = 2
three = 3

two = 4

You will see in the console that before you overwrite the variable, the print function will print the variable’s initially assigned value. After the overwriting line, print will print the variable’s new value because you’ve overwritten the data.

You’ve changed the value of the data inside the variable. When you call the print function, your computer looks at the last known value and prints it to you. When you modify the value, the value stored inside the computer gets changed.

Types of Variables

We’ve created variables (one, two, three) of a certain type: integers. They are integers because their values (1, 2, 3, 4) are integers (whole numbers). You can create other types of integers.

For instance, the following code creates a variable that is a decimal. Note that the name of the variable can be whatever you wish, but it is logical to name it something that relates to its value.

one = 

The preceding code declares a variable with the name one. one will be assigned the value on the other side of the operator. Let’s make the value 1 with the following code.

Decimal = 1.1

Another type of variable you can make is a string. Use the following format to create a new variable named StringVar (to stand for string variable.)


Notice that we capitalized the first letter of each word in this variable’s name. Although not required in Python, it is a naming convention and makes code easier to read.

A string is a series of characters. To declare a variable as a string, you can assign it a value in quotation marks. The following code gives StringVar the value "Hello".

StringVar = "Hello"

You can print this variable as well, using the same format for the print function.

StringVar = "Hello"

In Python, you don’t have to tell the computer what type you want a variable to be. Python automatically assigns a variable a type depending on the variable’s value. This differs from some other programming languages. You can simply assign a value, and the computer will store it in memory to be used later.

There are some rules, however. For instance, if you want to add a value to a variable, you can do so with the + operator. However, each variable can only be of one type. Let’s look at an example.

Suppose you want to add “1” to the end of StringVar. If you simply write + 1 to where you declared StringVar, you will get an error message. The console will print the TypeError “Can’t convert ‘int’ object to str implicitly.”

This error occurs because "Hello" is a string, whereas 1 is an integer. If you put quotation marks around 1, although 1 is still a number, the computer will interpret it as a string. You will no longer get an error message.

StringVar = "Hello" + "1"

All the variables we created are called global variables because they are not contained in any function. The variables are contained in the core of the code and aren’t in a subsection. As such, you can access them from anywhere.

An example of a local variable is a variable inside a function. For instance, the following code outlines how to set up a function. We provide more information on functions in our Python course.

def FunctionName(Input):
return Output

You can declare a variable inside the function like so:

def FunctionName():
newVar = "World"

As such, newVar is a local variable. It is local to a function. You cannot access newVar from outside the function. You can call the print function on newVar in the function. The console will print the value of the variable: World.

However, if you try to print newVar outside FunctionName, the code will crash. Because newVar is locally defined, it doesn’t exist outside the function. Your computer will give you the NameError “name ‘newVar’ is not defined”.

def FunctionName():
newVar = "World"


On the flip side, you can use global variables inside functions. For instance, you can call the one variable by simply typing its name in FunctionName. However, to let other developers know or to remind yourself that one is global, you can write the keyword global before the variable name.

def FunctionName():
global one
newVar = "World"

Comment out the line print(newVar) that is outside FunctionName so that we don’t get any errors. To comment out a line, add a hashtag to the beginning. The console will skip over any commented lines.

def FunctionName():
global one
newVar = "World"


Call print on one inside FunctionName. The console will print 1, the value of one that we defined earlier.

def FunctionName():
global one
print one
newVar = "World"

What else can you do with variables? There is another way to define variables that is a shorthand.

An alternate way to declare our variables one, two and three is with the following format:

one, two, three = 1, 2, 3

This code assigns the value 1 to one, 2 to twoand 3 to three.

What else can you do with variables?

You can create a new variable that is the sum of 2 values. For instance, the following code declares a variable five and assigns it the value 3+2. If you print five, the console will print the sum: 5.

five = 3+2

What can you not do?

You can’t use variables that are not yet defined. For instance, the following line would return an error because we have yet to declare a variable six.

five + six = 5

You also cannot declare a variable value-first. For instance, the following code would give the SyntaxError “can’t assign to literal”.

5 = five

This occurs because code to the left of the assignment operator (equals sign) is what you’re giving the value to, and code to the right of the sign is what the value is.

What are counting variables?

You will use counting variables a lot when programming. You can use counting variables to keep track of the number of times a certain event occurs. Let’s look at an example. Create a variable count, and give it the initial value 0.

count = 0

Call print on the count variable. Comment out all the other print lines so that you can clearly see what this example prints in the console. The console will print 0.

count = 0

Let’s make the value of count 1. There are several ways we can do this. One way we’ve already seen: to overwrite the value with the following code.

count = 0
count = 1

Another way is to add a value to the variable with the following code.

count = 0
count = count + 1

The preceding code assigns the value of count to be count’s current value plus 1. With a print function, the console would print 1.

You can increment count‘s value in this way because it will always add onto the latest value. For instance, assign count the value count + 1 again, and print it. The console will print 0 1 2.

count = 0
count = count + 1
count = count + 1

A shorthand notation to add a value to the current value of count is the following. This code will add to and redefine count.

count += 1

Similarly, you can multiply the value of count and reassign its value.

count = count * 3

There is shorthand notation for this, too:

count *= 3

The console will print 3 at this line.

You can divide the value of count and reassign its value.

count = count / 3

There is shorthand notation for this, too:

count /= 3

The shorthand is helpful because as you write more code, you will find that the more ways you can write less, the more efficient you will be as a coder.

Want to code more? Enroll in our Python course – on sale today.

In this course, you will learn how to code in the Python 3.5 programming language. Whether you have or have not coded before, you can learn how to use Python. Python is a popular programming language that is useful to know because of its versatility. Python is easy to understand and can be used for many different environments. Cross-platform apps and 3D environments are often made in Python.

We will cover basic programming concepts for people who have never programmed before. This course will cover key topics in Python and coding in general, including variables, loops, and classes. Moreover, you will learn how to handle input, output, and errors.

To learn how to use Python, you will create a functioning Blackjack game! In this game, you will receive cards, submit bets, and keep track of your score. By the end of this course, you will be able to use the coding knowledge you gained to make your own apps and environments in Python.

What students have said about our courses:

“He explains everything.. great course, great teacher.”

“The instructor tells us why we do things and breaks down everything so you will understand better.”

“Pace is excellent, iterates points without being redundant. Builds on previous knowledge in a very organic way.”

“Great course. Clear voice, good screen material. I liked it.”

“I absolutely love this course. I’m only part way through so far but felt compelled to leave a review. This is such a comprehensive course that was well worth the money I spent and a lot more!. Well done. Will definitely be looking at more Mammoth Interactive courses when I finish this.”

This course is project-based, so you will not be learning a bunch of useless coding practices. At the end of this course, you will have real-world apps to use in your portfolio. We feel that project-based training content is the best way to get from A to B. Taking this course means you learn practical, employable skills immediately.

Learning how to code is a great way to jump in a new career or enhance your current career. Coding is the new math and learning how to code will propel you forward for any situation. Learn it today and get a head start for tomorrow. People who can master technology will rule the future.

Get the course here!

6 skills every coder needs to get a job in 2018.

What it means to be a coder changes every year. Not only do you need hard skills (tech abilities), you also need soft skills, which concern the more human aspect of work.

1. The ability to take risks.

Image 1

Because projects can fail, it’s smart to have multiple streams of income. For example, if you design websites, have multiple projects going on at the same time. It is risky to take on a new project that you’re unsure will succeed. However, it’ll pay off in the long run because your income is diversified.

Get in the habit of making semi-predictable decisions and dealing with the loss. You must get comfortable with losing time or money on a project. The more comfortable you become, the more risks you’ll be able to take.

If you start a project – say, a game – and it fails, figure out what went wrong. Write down everything you can improve next time, and steps you can take to prevent the same things from going wrong. Then try again.

Even if a project fails, there is always something to learn from it. There will always be a next time as long as you don’t overextend on a project. By have multiple projects at once, you prevent yourself from overextending.

Be open to the risk it takes to accept new projects.

2. Self-Promotion

Image 2

In a world where the value of ‘me’ grows every day due to social media, your personal marketing skills become more important to your success as a coder. Not only are you marketing your skills – you’re marketing your personality.

A small business will look at what you’re like as a person to work with because they’ll be dealing with you every day. You have to be friendly but also know how to boast your talent.

Talking about yourself doesn’t have to feel sleazy. To be a tolerable – and better – self-promoter, simply talk about your projects and what you’re working on.

Be warm and open, and talk about your projects in a positive way. What you don’t want to do is spread negativity.

Self-promotion isn’t greedy. If you do it correctly, it is but a conversation.

3. Adaptability

Image 3

As technology changes, you have to keep learning. If you work at a small business or tech company, you might get new management or change locations or working styles. You have to be adaptable to what life throws you. I say, this keeps life interesting!

4. Clear Communication

Image 4

As a coder, understanding your team is crucial when working on projects. To deliver effective communication, think before you speak. When you talk to someone in person, bide your time before blurting out a response.

You can use the objects around you to fill time while you mentally form a clear response. When you meet someone for coffee, use your coffee cup to distract the person with an action while you think.

Alternatively, say, “Hmm, that’s a good idea,” and pause for a second. This shows your conversation partner that what they said requires your reflection. They’ll appreciate this – people love it when you think about what they say.

Of course, the way you offer communication varies with each situation. While going out for coffee with friends, you can respond slower and sit more casually than when you’re at a job interview that requires you to be professional and ready to answer.

If you do have miscommunication with someone, get feedback from the person on what you can alter so that the same miscommunication doesn’t happen again.

5. Long-Distance Communication


Image 5

Not only do you have to be able to communicate clearly in person, you also have to be able to do so online. To maintain a close connection with a virtual team, set up a team chat. A team chat is a chatroom where you can talk to your team members.

A team chat is a great place to share information about your project or have a bit of fun. Because technology is so prevalent in our daily lives, it’s only natural to have a digital conversation with your coworkers about topics. You can post anything like funny videos or gifs in this team chat.

There are many different programs that you can use for team chat. We at Mammoth Interactive use Discord, which allows us to categorize our conversations.  

6. Divergent Thinking

Image 6

Get inspiration from outside your field. Even if you’re a coder, this doesn’t mean you have to only watch coding tutorials. Learn about an adjacent topic, such as design. This will allow you to cross-pollinate your ideas and skills, which will increase your creativity.

Even if you think, “I never use this skill at my job,” you’ll surprise yourself by being able to apply a seemingly unrelated skill that you watched a short tutorial on. Fast, compact courses are great for this. We have many courses perfect for this kind of learning, including:

Divergent learning and thinking will make you better at reverse-engineering ideas. After all, it’s been said there’s no such thing as a new idea but rather the same one changed around for the times.

Reverse-engineering is like taking apart a clock and rebuilding it. It means getting inspiration from what’s popular in order to stay relevant and, well, in business.

To learn more about skills that will better yourself as a candidate in your field, enrol in our Soft Skills course.

Sign up for our newsletter.

Attend our webinars to get free courses.

Mammoth Interactive has 2 webinars coming up that you don’t want to miss. Get all the details below:

1. Introduction to Core ML *Includes FREE $500 Course!


Webinar Image

Learn about Apple’s new machine learning framework for iOS. Get the power of machine learning in your mobile app! In this webinar, developer John Bura discusses Core ML, which allows you to integrate automated tasks into Apple apps you develop.

FREE GIFT: Your ticket includes FREE access to the best-selling Mammoth Interactive course Mastering Core Image: XCode’s Image Recognition and Processing Framework ($500 VALUE)

Register for Thursday, Nov 30, 2017 (9:30 AM PST)


  • 9:30 – 9:35 – John introduces attendees to the webinar.
  • 9:35 – 9:40 – John gives you a background of his career and Mammoth Interactive. John lets you know the way we do webinars.
  • 9:40 – 10:20 – John introduces Core ML in Xcode 9 for iOS 11.
  • 10:20 – 10:30 – The last 10 minutes are an opportunity for you to ask John anything during a Q&A! John also provides information about upcoming webinars.

2. Get Good at Programming Quickly *Includes FREE $500 Course!

Webinar 2 Image

Do you want to be a coder? Join us to learn tips and tricks to get good at any programming language in as little time possible. Programmer John Bura discusses:

– The best ways to learn online
– Coding schools – good or not?
– Should you get a computer science degree?
– How to set up a good portfolio
– Interview questions for coding jobs

FREE GIFT: Your ticket includes FREE access to the best-selling Mammoth Interactive course Introduction to React and Redux. Code Web Apps in JavaScript ($500 VALUE)

Register for Tuesday, Dec 5, 2017 (9:30 AM PST)


  • 9:30 – 9:35 – John introduces attendees to the webinar.
  • 9:35 – 9:40 – John gives you a background of his career and Mammoth Interactive. John lets you know the way we do webinars.
  • 9:40 – 10:20 – Learn how you can become a programmer through self-directed learning. Get advice from experienced coding instructor John.
  • 10:20 – 10:30 – The last 10 minutes are an opportunity for you to ask John anything during a Q&A!

NOTE: By registering, you will be able to access each webinar recording after the livestream.

Our seats are 12$ for a limited time only – Reserve your spot today!

New course! A Comprehensive Beginner’s Guide to Coding in Kotlin

Learn to code for Android app development in Mammoth Interactive’s latest course. A Comprehensive Beginner’s Guide to Coding in Kotlin is perfect for beginner coders or anyone wanting to learn Java’s replacement language.


Kotlin is the brand-new programming language for Android app development that is taking Java by storm. Join programming expert Nimish Narang in this course on the basics of Kotlin. Nimish has extensive experience teaching app development as an instructor at Mammoth Interactive. Start learning to code today in this Number 1 course on Kotlin.

Is this course for me?

This course is devoted to Kotlin’s language basics and comparing the syntax to Java. We target beginners and cover core topics in depth. If you’re an intermediate or advanced coder, you can watch the videos at a faster speed using the Speed tool. We encourage you to follow along with the coding as we show you Kotlin’s unique syntax.

What Will I Learn?

1. The major concepts involved with variables, basic types of variables, more advanced types, Kotlin’s new syntax for variables, and how we can use variables differently in Kotlin than you may have already seen in other programming languages.

2. Collection types, which Kotlin allows us to customize. We’ll begin by looking at the simple collection types and then look at more advanced ones.

3. Control flow. Kotlin has some new statements not found in Java. Kotlin also provides the brand-new ability to turn control flow statements into expressions, which is a powerful capability that has a lot of potential. We will look at the basics and syntax, always relating back to real-life examples.

4. Functions, which have significant syntax differences in Kotlin. Beginners will learn how to use functions, and more advanced developers will benefit from the introduction to Kotlin’s new syntax.

5. Classes, objects, and other structures available in Kotlin.

Why Should I Learn Kotlin?

Kotlin is an innovative programming language for app development. You don’t have to use Java to make Android apps anymore! With Kotlin, you can write concise and powerful code. Kotlin is awesome because it is compatible with existing Java-based technologies.

Throughout the course, we will compare Kotlin and Java. Java is a popular programming language that many developers use to create content for the Web. Kotlin is a lot more syntactically flexible than Java. This allows you to have more fine control over how you write code to accomplish the tasks you want. You can insert an aspect of personality into code and write it how you want it to be read. It’s easy to incorporate Kotlin into existing projects and applications.

What are the requirements?

  • A working computer onto which you can install Kotlin and Android Studio
  • Java coding skills are helpful but not required

Take this course to learn how to code apps faster in an emerging programming language. Enroll today to join the Mammoth community.

ENROLL NOW for 19$.

 Stay in touch with us:

Exciting announcements from Mammoth Interactive.

We’re excited to announce our newest courses. Get each for only 19 dollars with these special offers.

Do you want to learn to build beautiful, well-functioning web apps? Join web developer Chris Veillette in this course for beginners to start building web apps today.

Introduction to React and Redux is full of practical examples. We teach you theory while also building real projects that you can put in your web development portfolio. Enroll today to join the Mammoth community.

Introduction to React and Redux. Code Web Apps in JavaScript. 96% off

If you want to learn to code for the web, Beginner’s ES6 Programming is the place to start. Begin your career or hobby in web development today by enrolling in this course.

In Beginner’s ES6 Programming, you will learn the fundamentals of coding in JavaScript, including ES6. You will learn how to change what is displayed on a webpage using JavaScript.

No prior experience in JavaScript is required. 

Beginner’s ES6 Programming. Code for the Web in JavaScript. 96% off

In Beginner’s Guide to Elm Programming, web developer Chris Veillette will teach you how to code in the Elm language to build real websites and apps.

Elm is a programming language that you can use to build web apps. Elm is user-friendly, which makes it a great place to learn to build web apps.

Beginner’s Guide to Elm Programming. Build Web Apps! 96% off

In Mastering Core Image, you learn how to add unique features to the images in your apps. A CIImage is a representation of an image that can be altered with Core Image filters. These filters allow users to change and interact with images in cool and useful ways.

Mastering Core Image: XCode’s Image Recognition and Processing Framework. 96% off

Want to make apps and learn to code? With The Ultimate iOS 11 Course, you too can design and code practical apps from scratch. Expert programmers John Bura, Nimish Narang, and Chris Veillette from Mammoth Interactive will teach you everything you need to know to whet your palette in iOS 11.

The Ultimate iOS 11 Course. Learn to Build Apps! 96% off