In this tutorial you will learn:
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?
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.
- myVariable = 1
- myVariable2 = 2
- myCharacter = ‘a’
- 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:
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