Professional Documents
Culture Documents
Now that you have a good command on previous chapter, let's do something more.
print(type('Hello World'))
print(type(8))
print(type(8.0))
Output
<class 'str'>
<class 'int'>
<class 'float'>
'type()' gives us the type of anything given to it. For example, type("Hello
World") is 'str'. str understands for string.
Even a digit written inside ' ' or " " is treated as a string and not as an integer
or a decimal. For example, print(type("8")) will give us <class 'str'>.
Let's brush-up.
Output
<class 'str'>
<class 'int'>
<type 'class'>
I am learning something new.
10
3.14
Python Keywords
There are few words which are used by Python language itself. So, we can't
use those words for the name of our variables as they are reserved for the
Python. For example, del is used to delete objects and using it for the name
of a variable will give us an error.
print('Fun'*3)
Output
FunFunFun
Output
ab
Working!
This is the Pythonic way to get your things done. These type of features of
Python can be of good use for you in future.
Commenting
You can also include something in your code which won't be compiled and your
computer will simply ignore that while running your code. Comments are written
to make our code more readable. Comments are written after '#'. Comments
written after '#' are single line comments. New line will not be a part of
the comment
# I am using a variable x
x = 10
print(x)
Output
10
You can also use multi-line comments. To use them write comments between ( '''
''' ). Let's see this.
'''Multiline comment
Using variable x and y.'''
x = 10
y = 5
print(x+y)
Output
15
Why to use comments?
Swap
x = 10
y = 5
x,y = y,x
print(x)print(y)
Output
5
10
And it's done. Yes, I know it is easy and that's why I love Python.