Printing A List Using Python

Understanding the functionality of print() function in python. The print() function is used to display any type of data in a human-friendly format. It can be used on almost any kind of variable you ca …

Updated October 4, 2023

Understanding the functionality of print() function in python. The print() function is used to display any type of data in a human-friendly format. It can be used on almost any kind of variable you can think of.

# define a list
list_1 = [1, 2, 3, 4, 5]

# print the whole list
print(list_1)

# print each item in the list on separate line
for i in list_1:
    print(i)

In this example, the print() function is used to display a list of integers. It first prints the entire list, and then it uses a loop to iterate through every item in the list and print it individually. These are all basic examples and Python’s print function has many more features like using “end” argument or customizing the format of output.

Stay up to date on the latest in Coding Python with AI and Data Science

Intuit Mailchimp