In [ ]:
*** print() ***
In [ ]:
First, I have learned the command print. The command print is a function, print(). It should be used with parentheses.
Case also matters. It should be in lowercase as most Python commands are in lowercase.
In [1]:
print("Hello, world!")
Hello, world!
In [ ]:
As you can see anything inside quotes will be printed onto the screen exactly as it appears. You can type anything inside
quotes: letters, numbers or characters.
In [3]:
print(" I have 3 pencils... ")
I have 3 pencils...
In [4]:
Print("Got an error message because case matters.")
--------------------------------------------------------------------------- NameError Traceback (most recent call last) Cell In[4], line 1 ----> 1 Print("Got an error message because case matters.") NameError: name 'Print' is not defined
In [ ]:
We can use the command print() without quotes, too.
In [6]:
print(2)
2
In [ ]:
The command print() just returns that number when we do not use quotes around the number.
In [7]:
print(2*3+5)
11
In [ ]:
It returns the result of the arithmetic expression. If we use parentheses around the expression, it will return the expression
exactly as it is.
In [8]:
print("2*3+5")
2*3+5
In [ ]:
Anything inside quotes is called a string that is a combination of letters, numbers and characters. Below are some more
examples:
In [3]:
print("Enter a number: ")
print(9/5-2*3+4)
print("9/5-2*3+4")
Enter a number: -0.20000000000000018 9/5-2*3+4
In [ ]: