Hello friends, in this article, we will see how to use the print structure in Python with a few examples. The print command is simply as belows.
print(object(s), sep=separator, end=end, file=file, flush=flush)
Here ;
We add the object that we will print to the screen as much as we want in the object(s) parameter part.
In the sep=separator parameter part, we determine how to separate the objects entered in the object part. Ex: We separate Apple and Pear with a comma using sep=",”. This feature is optional.
end=end This property is optional. At the end it is indicated what to write.
file=file This property is optional. It is an object with a write method. sys.stdout is selected by default.
flush=flush This property is optional. It is a Boolean value. The default value is False.
print(*objects, sep=' ', end='\n', file=sys.stdout, flush=False)
In our first example,
print ("Hello", "How are you ? ")
print ("") # we leave a blank line..
print ("Merhaba", "Nasilsin ? ")
Figure 1
In our second example,
fruits=("apple","pear","cherry", "strawberry","banana","grape")
print(fruits)
Figure 2
In our third example,
We will write the result of the multiplication of the two entered numbers on the screen.
a=2
b=3
result=a*b
print("Result (2*3) =" + str(result))
Figure 3
In our last example,
array1 = [1,2,3,4,5]
array2 = ("A","B","C","D","E")
str1 = "Hello"
str2="Bahadir"
str3="How are you ? "
print(array1,array2,str1,str2,str3, sep="-", end=("..."))
Figure 4
We have come to the end of this article. See you in our next article. Happy coding. Bahadir Sahin
No comments:
Post a Comment