O GoConqr está de visual novo! Conte para nós o que você achou.

Módulo 7 de 13 · Texto

Replication

David Khieu

Replication

The * (asterisk) sign, when applied to a string and number (or a number and string, as it remains commutative in this position) becomes a replication operator:

 

string * number
number * string

It replicates the string the same number of times specified by the number.

For example:

  • "James" * 3 gives "JamesJamesJames"
  • 3 * "an" gives "ananan"
  • 5 * "2" (or "2" * 5) gives "22222" (not 10!)

REMEMBER

A number less than or equal to zero produces an empty string.

This simple program "draws" a rectangle, making use of an old operator (+) in a new role:

print("+" + 10 * "-" + "+")
print(("|" + " " * 10 + "|\n") * 5, end="")
print("+" + 10 * "-" + "+")

Note the way in which we've used the parentheses in the second line of the code. 

Try practicing to create other shapes of your own artwork!

 

Instruções

Para avançar no curso, envie uma tentativa deste quiz. Você pode enviá-la depois da última pergunta.

Ir para o módulo escolhido

Fale Conosco

Sobre o que é sua mensagem?

O que você acha do novo visual?

Você gostou?