Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python List All Squares of a Number List

Python List All Squares of a Number List

Document Object Reference Manual Python3 Examples

We will use Python to write a simple program that accepts a list of numbers and returns a list of their squares.

Example

numbers

=

[

1

,

2

,

3

,

4

,

5

]

squares

=

[

n**

2

for

n

in

numbers

]

print

(

squares

)

Code analysis:

Output result:

Example

[

1

,

4

,

9

,

16

,

25

]

Document Object Reference Manual Python3 Examples