Industry-relevant training in Business, Technology, and Design to help professionals and graduates upskill for real-world careers.
Fun, engaging games to boost memory, math fluency, typing speed, and English skills—perfect for learners of all ages.
Enroll to start learning
You’ve not yet enrolled in this course. Please enroll for free to listen to audio lessons, classroom podcasts and take practice test.
Read a summary of the section's main ideas. Choose from Basic, Medium, or Detailed.
This section covers how to use the print() function to display multiple values simultaneously. It highlights the use of commas to separate outputs and illustrates how to format those outputs using the 'sep' parameter for custom separators.
The print()
function in Python allows developers to output multiple values in a single command, which helps keep the code concise and more readable. By separating the items with commas within the print()
function, programmers can easily display complex outputs. For instance, writing `print(
Dive deep into the subject with an immersive audiobook experience.
Signup and Enroll to the course for listening the Audio Book
The print() function can take multiple arguments, separated by commas.
In Python, the print() function is versatile and allows you to display more than one value at a time. When you use the print() function, you can pass in various arguments separated by commas. This means you can show multiple pieces of information in a single output line, which is quite useful for combining text and variable values together.
Imagine you're a teacher giving feedback to a student about their grades. Instead of saying individual statements like 'Your math score is 90' and 'Your science score is 85', you could say 'Your scores are: 90 in math and 85 in science.' This is similar to how you can print multiple values at once in Python.
Signup and Enroll to the course for listening the Audio Book
Example:
a = 5 b = 10 print("The values are", a, "and", b)
Output:
The values are 5 and 10
In this example, we have two variables, 'a' and 'b', assigned the values 5 and 10, respectively. When we use the print() function with these variables along with some text, Python combines them into one cohesive output. The text 'The values are' is printed first, followed by the value of 'a', then the text 'and', and finally the value of 'b'. This demonstrates how easily you can display multiple values in a single line.
Think of it as introducing a pair of friends at a party. Instead of saying just one name at a time, you could say 'This is Sarah who is 22 years old and this is Jack who is 24 years old.' You're using one statement to convey information about both friends.