# Sage Range function

I use sage range function to print numbers form 1 to say 10 using print [1..10]. How to print only even numbers using this?

Sage Range function

asked
**
2017-09-17 12:49:48 -0500
**

This post is a wiki. Anyone with karma >750 is welcome to improve it.

I use sage range function to print numbers form 1 to say 10 using print [1..10]. How to print only even numbers using this?

4

The ellipsis operator looks at the previous two numbers to guess the step.

```
sage: [2, 4 .. 10]
[2, 4, 6, 8, 10]
```

0

using list comprehension:

```
sage: [i for i in [1..10] if i%2==0]
[2, 4, 6, 8, 10]
```

see more alternatives in the Programming in Python and Sage Thematic Tutorial.

Asked: **
2017-09-17 12:49:48 -0500
**

Seen: **197 times**

Last updated: **Sep 17 '17**

'int' object has no attribute 'is_prime'

Permutations indexed from zero

Error when using 'for in range()' but not ' for in [..]'

range and division : unexpected behavior

Determine domain and range of linear equation?

Define range of y axis, instead of just x axis?

Copyright Sage, 2010. Some rights reserved under creative commons license. Content on this site is licensed under a Creative Commons Attribution Share Alike 3.0 license.

Is the following ok?

I knew that. I was wondering if same can be done with [1..10]?