range() Sequência de inteiros
Última atualização: 2026-09-22
range() Sequência de inteiros
range(stop) ou range(start, stop[, step]) retorna um objeto de sequência imutável de inteiros. Frequentemente usado com laços for.
| Categoria | Funções internas |
|---|---|
| Tipo | Função interna |
| Versão do Python | all |
📝 Sintaxe
range(stop)
range(start, stop[, step])
⚙️ Parâmetros
| stop Obrigatório | The end value (exclusive); required. |
|---|---|
| start Opcional | The start value (inclusive); defaults to 0.(Padrão:0) |
| step Opcional | The step; defaults to 1; must not be 0.(Padrão:1) |
Retorno:An immutable range object of integers; iterable, sized, and indexable.
💥 Exceções
TypeError— Raised when an argument is not an integer (or lacks __index__).ValueError— Raised when step is 0.
▶ Exemplo
Edite o código, clique em Executar e veja o resultado no painel de saída:
Saída:
[0, 1, 2, 3, 4]
[1, 3, 5, 7, 9]
🏷️ Funções internas relacionadas
💡 Casos relacionados
Mais estudos de caso em breve — aguarde.
❓ Perguntas frequentes
QPor que list(range(5)) é [0,1,2,3,4] em vez de ir até 5?
Arange é um intervalo meio-aberto — stop não é incluído; para obter 1-5 use range(1, 6).
QO que range(1, 10, 2) produz?
AProduz 1, 3, 5, 7, 9. step é o incremento; passar step 0 levanta ValueError: range() arg 3 must not be zero.
Qrange é uma lista? Usa muita memória?
ANão, é um objeto de sequência preguiçoso que guarda apenas start/stop/step, então range(10**9) quase não usa memória; mas suporta len(), indexação e o operador in.
QComo iterar em ordem reversa?
AUse um step negativo: range(10, 0, -1) gera de 10 até 1, e range(4, -1, -1) gera de 4 até 0.