This blog assumes that you have a Linux machine with Python already installed.
If you don't, then you can use an AWS cloud based image with Python. For guidance, refer to my blog.
I am using Python 2.7 for this tutorial.
VARIABLES
Variables in Python are declared simply as follows.
variable = value
The data type of the variable is automatically assumed based on the value you provide.
a = 2
The above is an example of declaring and assigning a value to variable a. Since 2 is an integer, the data type automatically becomes integer.
Other examples:
b = 'String1'
c = " String2"
d = 3.2
d = 3.2
Notice that single or double or triple quotes can be used for strings.
d is a float.
Example Program-1
***************************************************************
#! /bin/python
int1 = 12
int2 = 14
int2 = 14
str1 = 'Abraham'
str2 = "Lincoln"
str2 = "Lincoln"
float1 = 5.4
float2 = 2.0
float2 = 2.0
# Print the values of the variable
print "\n int1 = ", int1
print "\n int2 = ", int2
print "\n float1 = ", float1; # Semicolon is optional if you love it so much!
print "\n float2 = ", float2
print "\n str1 = ", str1
print "\n str2 = ", str2, "\n"
print ("Done!"), str2
print "\n int2 = ", int2
print "\n float1 = ", float1; # Semicolon is optional if you love it so much!
print "\n float2 = ", float2
print "\n str1 = ", str1
print "\n str2 = ", str2, "\n"
print ("Done!"), str2
***************************************************************
No comments:
Post a Comment