How to Copy Lists and Generate a 9×9 Multiplication Table in Python
This article demonstrates two basic Python examples: copying a list using slicing and printing the full 9×9 multiplication table with nested loops, including the complete source code and expected output for each case.
Example 1
Task: Copy the data from one list to another.
Analysis: Use list slicing (list[:]).
#!/usr/bin/python
# -*- coding: UTF-8 -*-
a = [1, 2, 3]
b = a[:]
print(b)Output:
[1, 2, 3]Example 2
Task: Print the 9×9 multiplication table.
Analysis: Use two nested loops, with i controlling rows and j controlling columns.
#!/usr/bin/python
# -*- coding: UTF-8 -*-
for i in range(1, 10):
for j in range(1, 10):
result = i * j
print('%d * %d = % -3d' % (i, j, result))
print('')Sample output (partial):
1 * 1 = 1
1 * 2 = 2
1 * 3 = 3
1 * 4 = 4
1 * 5 = 5
1 * 6 = 6
1 * 7 = 7
1 * 8 = 8
1 * 9 = 9
2 * 1 = 2
2 * 2 = 4
2 * 3 = 6
2 * 4 = 8
2 * 5 = 10
2 * 6 = 12
2 * 7 = 14
2 * 8 = 16
2 * 9 = 18
... (continues for rows 3 through 9) ...Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Python Programming Learning Circle
A global community of Chinese Python developers offering technical articles, columns, original video tutorials, and problem sets. Topics include web full‑stack development, web scraping, data analysis, natural language processing, image processing, machine learning, automated testing, DevOps automation, and big data.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
