Math in Strings
You've examined that the +
operator can be applied to statements that are related to one data type: concatenate strings, add some numbers, etc. But please look at this simple example where input and output are pretty understandable for you:
1print(12 * 4)
However, multiplication works not only with equal data types, but with various ones too. This means that we can multiply your string by a number. For instance, if we multiply it by 2, the string will be printed twice. Take a look at the following example:
1print('12' * 4)
Note
We can multiply a string only by an integer number.
Swipe to start coding
You're creating a dynamic banner for a marketing page. Sometimes, to grab attention, you need to repeat catchy phrases. In this task, you'll practice string repetition in Python.
- Repeat the value of
heading_text
2 times and assign it torepeated_heading
. - Repeat the value of
subheading_text
3 times and assign it torepeated_subheading
.
Solución
¡Gracias por tus comentarios!
single
Pregunte a AI
Pregunte a AI
Pregunte lo que quiera o pruebe una de las preguntas sugeridas para comenzar nuestra charla
Resumir este capítulo
Explicar el código en file
Explicar por qué file no resuelve la tarea
Awesome!
Completion rate improved to 3.03
Math in Strings
Desliza para mostrar el menú
You've examined that the +
operator can be applied to statements that are related to one data type: concatenate strings, add some numbers, etc. But please look at this simple example where input and output are pretty understandable for you:
1print(12 * 4)
However, multiplication works not only with equal data types, but with various ones too. This means that we can multiply your string by a number. For instance, if we multiply it by 2, the string will be printed twice. Take a look at the following example:
1print('12' * 4)
Note
We can multiply a string only by an integer number.
Swipe to start coding
You're creating a dynamic banner for a marketing page. Sometimes, to grab attention, you need to repeat catchy phrases. In this task, you'll practice string repetition in Python.
- Repeat the value of
heading_text
2 times and assign it torepeated_heading
. - Repeat the value of
subheading_text
3 times and assign it torepeated_subheading
.
Solución
¡Gracias por tus comentarios!
Awesome!
Completion rate improved to 3.03single