Python Programming Environment Setup
First step is to set up the development environment.
You will need to download Python form here: http://www.python.org
What is a Variable?
A variable is a container where data is stored.
The data can be of any type.
Below you will find the definition of different data types.
Note: Unlike some other programming languages like Java in Python you do not have to declare the variable types.
A variable of type int is used to store integral values such as 1, 105 and 0.
age = 12 length = 300
Float or Floating Point Number
A variable of type Float is used to store decimal numbers such as 1.4, 293.29 and -1322.76.
temperature = 18.5
Boolean or bools
A Boolean data type can hold one of two values:
result = "True"
A String data type holds a collection of characters known as a string.
name = "Tom" colour = "Green"
Printing Data Types with Python
The print() function is used for printing data types. More on functions later.
print "Python Programming is fun!"
Alternatively , you may want to store the string value in a variable and then print its value. In both cases “Python is cool!” will be printed in the output console.
myString = "Python Programming is fun!" print myString;
Simply put, the assignment operator assigns a value to a variable.
temperature = 35
After the above assignment, temperature variable holds a value of 35
Note that the value assigned can be changed later. In which case, the variable will hold the new value.
here we say:
temperature = 40
The variable now holds a value of 40.
|a += b||is equivalent to||a = a + b|
|a -= b||is equivalent to||a = a – b|
|a *= b||is equivalent to||a = a * b|
|a /= b||is equivalent to||a = a / b|
|a **= b||is equivalent to||a = a **b|
|a %= b||is equivalent to||a = a % b|
Arithmetic operators are used for mathematical calculations.
Addition (+), Subtraction (-), Multiplication (*) and Division (/)
((4 + 5 - 6) * 7 / 5)
3 ** 3
This is equivalent to 3 to the power of 3 and will return 27.
a % b will return the remainder of a/b
14 % 4
14/4 returns 3 with a remainder of 2. Therefore 14 % 4 returns 2.
The comparison operators returns a boolean.
In other words they return True or False.
a == b a < b a > b