In [ ]:
*** print()-->part-2 ***
In [ ]:
If we use the command print() with a word inside the parantheses without quotes, we will get an error message.
In [1]:
print(age)
--------------------------------------------------------------------------- NameError Traceback (most recent call last) Cell In[1], line 1 ----> 1 print(age) NameError: name 'age' is not defined
In [ ]:
The word "age" is not in quotes. Python will not interpret it as a string anymore. Then, what is it? What should we do not to
get an error message? The words without quotes inside parantheses of the command print are called variables. Variables in
programming are used to store information like numbers and strings. If we will use a variable with print(), we should define
that variable in advance.
In [3]:
age = 34
print(age)
34
In [ ]:
Now we won't get any error message. This is just one way to define variables before using them. The other way is to use
the command input().
In [5]:
print("*****")
print("*****")
print("*****")
***** ***** *****
In [ ]:
These three commands will print a box of stars "*". Note that after the execution of each print function, the cursor will move
automatically to the next line. We can use an optional argument called "end" to keep the cursor in the same line.
In [6]:
print("My name is ", end=" ")
print("George.")
My name is George.
In [7]:
print("3 + 7 =", end="")
print(3+7)
3 + 7 =10
In [ ]:
We used the argument "end" here without space inside quotes. Also, we could have used only one print function for the sake
of brevity.
In [8]:
print("3 + 7 = ", 3+7)
3 + 7 = 10
In [9]:
print("*****")
print("* *")
print("* *")
print("*****")
***** * * * * *****
In [10]:
print("#")
print("##")
print("###")
print("####")
# ## ### ####
In [ ]: