After doing the installation and try on familiarize with IDLE Python and editor window, in this post, let's try to dig deep on print() function.
Run the IDLE,
Enter the following command :
print("Anityo Nugroho")
The result will be :
Anityo Nugroho
Next :
print("Anityo Nugroho","engineer")
The result will be :
Anityo Nugroho engineer
Another example which is variable :
blog="Beginner in Python"
print(blog)
The result will be :
Beginner in Python
The above example in IDLE :
Let's combine variable with another string :
print(blog,"Anityo Nugroho")
The result output will be :
Beginner in Python Anityo Nugroho
Next, to try the output using integer :
print(25)
It will give the output :
25
Other example using decimal number :
print(358.22458)
Result will be :
358.22458
There is a difference in Python when we use strings and number for print() function. Number, can be entered without quotation marks and also strings in the form of variable.
Separator
Let us try some examples on separator :
print("Anityo","Nugroho","Graham","Aker"); print()
print("Anityo","Nugroho","Graham","Aker",sep="\t"); print()
print("Anityo","Nugroho","Graham","Aker",sep="|"); print()
print("Anityo","Nugroho","Graham","Aker",sep=""); print()
The output will be :
the second print() on every line added using a ; semicolon, to gives a line space between each equation.
The different between the first and second example, with sep="\t" as separator, output of the following names with a tab between each name.It is the same if we apply on numbers, example :
print(12,24,36,48,sep="**")
It will give the output :
12**24**36**48
Other separator that like to try is \n
Example :
print("Python","\n","Beginner Walk","\n","year 2018","\n"); print()
print("Python","Beginner Walk","year 2018",sep="\n"); print()
it will give output :
To avoid spaces between output (like on example 1), addition of \n as separator just once in the code (example 2).
Let's work with output on both string and number :
Example :
print("Anityo Nugroho,38"); print()
print("Anityo Nugroho",38); print()
Result will be :
The following codes to make a good quote :
The output will be :
Comments
Post a Comment