Page 192 - Data Science Algorithms in a Week
P. 192
Python Reference
Comments
Comments are not executed in Python, start with the character #, and end with the end of
the line.
Input:
# source_code/appendix_c_python/example01_comments.py
print "This text will be printed because the print statement is executed."
#This is just a comment and will not be executed.
#print "Even commented statements are not executed."
print "But the comment finished with the end of the line."
print "So the 4th and 5th line of the code are executed again."
Output:
$ python example01_comments.py
This text will be printed because the print statement is executed
But the comment finished with the end of the line.
So the 4th and 5th line of the code are executed again.
Data types
Some of the data types available in Python are:
numeric data types: int, float,
Text data types: str
Composite data types: tuple, list, set, dictionary.
Int
The int data type can hold only integer values.
Input:
# source_code/appendix_c_python/example02_int.py
rectangle_side_a = 10
rectangle_side_b = 5
rectangle_area = rectangle_side_a * rectangle_side_b
rectangle_perimeter = 2*(rectangle_side_a + rectangle_side_b)
print "Let there be a rectangle with the sides of lengths:"
print rectangle_side_a, "and", rectangle_side_b, "cm."
print "Then the area of the rectangle is", rectangle_area, "cm squared."
[ 180 ]