Python Tutorial: How To Repeat Strings in Python? - Python Strings #46

preview_player
Показать описание
How to Repeat Strings in Python?
In the previous tutorial we saw how to combine strings together in this tutorial we are going to look at how repeat strings in Python in this tutorial. There may be a time where it would be easier to repeat a string using repetition over typing the string over and over. I am lazy so if I have to type something for a second then I use repetition. We can repeat a string using the repetition(* - asterisk) symbol and then followed by an integer representing how many times you would like to repeat the string. Let's take a look at few examples of how to do this in Python.

Examples of How To Repeat A String In Python
#Repeat the line twice
'This we be repeat twice' * 2
'This we be repeat twiceThis we be repeat twice'

#repeat no 5 times using a variable
a = 'no'
a * 5
'nonononono'

#Repitition and Concatenation
b = 'yes'
a * 5 + b * 5
'nononononoyesyesyesyesyes'
Repeating strings in Python is pretty straight forward if you have any questions leave a comment below and we will help you out.
Рекомендации по теме
Комментарии
Автор

What I am searching is exactly put here 👍

Автор

I've been watching your tutorials for about 2 weeks and finally its starting to make sense thanks for the time you put into these videos. they can be slow to begin but you explain the basics which is key to learning properly.

louis
Автор

How do you get a new line for each repeat because the print(a*b\n) does not work???

radieter
Автор

How can i repeat a string 100 times but 1 string per line

BrianTheLog
visit shbcf.ru