- Get link
- X
- Other Apps
- Get link
- X
- Other Apps
PYTHON tutorial part-2
Let’s start the lesson with an example,
#Example program
print("Hi friends!")
This code prints "Hi friends!" to the screen.
print() function:
The print() function helps to print a string or variable or anything to a screen. If you want to give more than one value, you could use a comma to separate them.
Syntax:
print(var1,var2,"string",...[end="",sep=" ",file=file,flush=flush])
In above inside square brackets are optional.
Parameters:
- var1,var2
- These can be values or variables or expressions to display.
- end
- It decides to finish a print() with the given value. (Default value is "\n")
- sep
- sep is a separator for given arguments of the print() function. (Default value is " ")
Printing some values:
>>>print("Learnallsimply")
Learnallsimply
>>>print(10+10)
20
In the above, we printed a string and a maths operation.
Using separator:
>>>print("Hi","friends!",sep="|")
Hi|friends!
>>>print("Welcome","to","all",sep="\n")
Welcome
to
all
>>>
In the above snippet, we separated all given strings using 'sep'. '\\n' is one of the escape sequences. It returns a new line to a screen. We will learn about that in later lessons.
Using end:
Have a look at the below code
#In a script mode
print("Hi")
print("friends!")
Output:
Hi
friends!
In the above example, the print function printed them between a new line.
Suppose if we want to make thems ends with a comma or anything? "end" makes these situations easy.
#In a script mode
print("Hi",end=",")
print("friends!",end="👍")
Output:
Hi,friends!👍
Here a first string ends with a comma and a second string is ends with thumbs up.
Try here what you learned
COMMENTS IN TAMIL ARE ALSO WELCOME.
- Get link
- X
- Other Apps
Comments
Nice for the topic
ReplyDeleteKeep it up