Programming in Python

1. Introduction to Python

Type the below code in the IDLE and check the output.


Use the following codes to perform basic arithmetic operations.
2**3 means 2 to the power of 3 which gives a result of 8 whereas 2*3 just multiplies 2 and 3 which gives a result of 6.

Lets print a sentence
print("Hi, Welcome all")

Now, lets store the number in an object
a = 10

Now, print the value of a

Comment line in python
Note that the commands following with '#' wont't be executed but will be displayed

Now, lets store the another number in an object
b = 30

Multiply a and b and print the result

Let's print the string 'Hello' 10 times
print("Hello" * 10)
print("Hello" * a)

Both the statements will print 'Hello' 10 times because we have stored the value 10 in 'a'
Now, lets add two strings
print("Hi, " + "how are you?")

Try to add different datatypes
print("Hi" + 10)
This will throw a TypeError: can only concatenate str (not "int") to str

Now, we should understand what are the different datatypes available in python which will be covered in the next section