In python there are many keywords which has different attributes. The keyword has special attribute to the python language. Example int is a keyword which is used to declare a variable with integer type. Similarly there are many keywords which we can used in python.
In python, based on the values we are assigning, the datatype of the variable is automatically assigned while in the other programming language we want to declare the datatype for every declaration. If we declared a=1, the compiler will automatically assign the datatype of a as integer. If we assign a=1.5, the compiler will automatically assign the datatype as float.
Reading Values through Keyboard
In python we can read the values from the keyboard in a easy way.
number = int(input(” Enter the number ” )
Thus when we execute the program, it will show “Enter the number” and ask the user to enter the number. To read the values,we want to declare the datatype of the input.
Assigning a Variable
The variable can be assigned in different ways in python. But the assignment is more easy compared to other languages.
a , b = 10, 20 # Thus the compiler will assign the value of a as 10 and the value of the b has 20
So by this way, Swapping of two numbers can be easily done.
a , b = b , a
The value stored in the a will be assigned to b and the value stored in b will assigned to will assigned to a. Thus when we print the value
print( a ) # The Output will be 20
print( b ) # The Output will be 10
Formatting Method
Python has various formatting methods in string. The most common and preferable method is .format method.
name = ” Chandru “
place = ” Chennai “
sentence = ” {0} lives in {1} “.format(name, place)
print( sentence )
When we print the sentence, {0} is replaced by the name and {1} is replaced by the place. The second method is f String.
name = ” Chandru ”
place = ” Chennai “
sentence = f” {name} lives in {place} “
print( sentence )
When we print this, the string which is stored in the variable name will be replaced and similarly for the place.