Skip to main content

Python Variables and Comments

Python Variables and Comments

In this tutorial you will learn:

  • Basics of Python
    • Commenting
    • Variables

Basics of Python

The first thing that one needs to understand in order to learn any programming language is the answer to the question what is a variable?

1. Variables

Variables are the containers where you store your values. They are essentially places in memory for storing data. These containers have different types for storing different types of data. Commonly used data types and their short hand syntax are:

Integer - Int - For storing numbers such as 1,2,3,4 ….

Float - Float - For storing numbers with a floating points e.g 1.91, 2.32, 5.68 etc

Character - Char - For storing characters e.g ‘a’, ‘b’, ‘c’ etc

String - String - For storing large strings e.g “This is my first python program”

In Python you don’t declare a type ( int, float, string etc ) explicitly. Assigning a value automatically declares a variable for you and the data type is handled by python implicitly.

  1. myVariable = 1
  2. myVariable2 = 2
  3. myCharacter = ‘a’
  4. myString = “I am a programmer”

It doesn’t mean there are no data types in python it’s just that it handled by python implicitly

print(type(myVariable); #would print int

you can explicitly type cast using

myVariable = int(1)

Important variable naming rules:

  • Alpha-numeric characters and underscores (A-z, 0-9, and _ ) can be used only.
  • Variable are case-sensitive ( name and Name are different variables ).

2. Write a comment

Comments aren’t part of the code that will later compile but they just explain your code to other developers. They won’t effect the running of your code in any way, writing them in the code will only make it more clear. That’s how you write a comment

# This is a comment

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.


1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

Add new comment

This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.