Professional Documents
Culture Documents
Python is known for its simplicity. So, let's tell the computer to say hello to us.
print("Hello World")
Output
Hello World
To print any message on screen, just type print() and that message in (' ') or (" "). Isn't
it simple?.
Output
Output
x = 10
y = 5
print("sum of",x,"and",y,"is",x+y)
Output
sum of 10 and 5 is 15
Here, x = 10 means that we are taking a variable x and giving it a value of 10.
print("sum of",x,"and",y,"is",x+y) → Take a note that "sum of", "and" and "is" are
written inside " " but x, y and x+y are not and these are seperated using commas (,).
Whatever we write inside " " or ' ' gets printed as it is and is not evaluated. So, 'Sum
of', 'and' and 'is' got printed as it is. But x, y and x+y are not written inside '
' or " ", so they are variables and the complier will use their value. That's why the
value of x got printed (i.e., 10).
Similarly, the value of y (i.e., 5) got printed and at last, the value of x+y got
calculated (i.e., 15) and got printed.
Take a note that using comma (,) also adds a space. For example, you can see a space printed
between "sum of" and 10 i.e., "sum of 10".
x = 10
print(x)
print('x')
Output
10
x
As you can see, 'x' printed x and x printed 10. This means that 'x' is simple
alphabetical x and x (without quotes) is a variable with a value of 10.
x = "Hello World"
print(x)
print('x')
Output
Hello World
x
By practice, you will learn these things more effectively. So, make sure to solve questions
from the Practice Section.
Take a notes that there is no difference between ' ' (single quotes) and " " (double quotes)
in Python which are different in many other languages.
x = 10
prin(x)
Here, we are trying to teach you, how to fix an error, if you got one.
NameError: name 'prin' is not defined → 'prin' is nothing for our program because it is not
defined anywhere in our program. That's why it is giving us an error.
Go back to your code and then to that line (prin(x)) and fix it.
In future, when writing long codes, make sure that you run your code from time to time while
writing instead of completing your whole code and running at last. This will make debugging your
code a lot easier.
- Chanakya