diff --git a/README.md b/README.md index d525798d3..1e318f953 100644 --- a/README.md +++ b/README.md @@ -117,6 +117,7 @@ * [`decapitalize`](#decapitalize) * [`is_anagram`](#is_anagram) * [`kebab`](#kebab) +* [`n_times_string`](#n_times_string) * [`palindrome`](#palindrome) * [`snake`](#snake) * [`split_lines`](#split_lines) @@ -1787,6 +1788,28 @@ kebab('AllThe-small Things'); # "all-the-small-things"
[⬆ Back to top](#contents) +### n_times_string + +Prints out the same string a defined number of times. + +Use this method to print out the same string n number of times. + + +```py +def n_times_string(str,n): + return (str * n) +``` + +
+Examples + +```py +n_times_string('py', 4) #'pypypypy' +``` +
+ +
[⬆ Back to top](#contents) + ### palindrome Returns `True` if the given string is a palindrome, `False` otherwise. diff --git a/snippet_data/snippetList.json b/snippet_data/snippetList.json index a56b243cd..691a7a121 100644 --- a/snippet_data/snippetList.json +++ b/snippet_data/snippetList.json @@ -807,6 +807,21 @@ "hash": "c920b58f01c63346e65eab83a60c4635d4c104e41767b9d41ad94029e662b902" } }, + { + "id": "n_times_string", + "type": "snippetListing", + "title": "n_times_string", + "attributes": { + "text": "Prints out the same string a defined number of times.\n\nUse this method to print out the same string n number of times.\n\n\n", + "tags": [ + "string", + "beginner" + ] + }, + "meta": { + "hash": "b8ba27a04a5c2dcd91f6643eb02b61b9df9a58bedea26ceb2042cb535c0c1eb1" + } + }, { "id": "none", "type": "snippetListing", diff --git a/snippet_data/snippets.json b/snippet_data/snippets.json index d6d6078e9..a4df75ffb 100644 --- a/snippet_data/snippets.json +++ b/snippet_data/snippets.json @@ -1067,6 +1067,26 @@ "hash": "c920b58f01c63346e65eab83a60c4635d4c104e41767b9d41ad94029e662b902" } }, + { + "id": "n_times_string", + "title": "n_times_string", + "type": "snippet", + "attributes": { + "fileName": "n_times_string.md", + "text": "Prints out the same string a defined number of times.\n\nUse this method to print out the same string n number of times.\n\n\n", + "codeBlocks": { + "code": "def n_times_string(str,n):\r\n return (str * n)", + "example": "n_times_string('py', 4) #'pypypypy'" + }, + "tags": [ + "string", + "beginner" + ] + }, + "meta": { + "hash": "b8ba27a04a5c2dcd91f6643eb02b61b9df9a58bedea26ceb2042cb535c0c1eb1" + } + }, { "id": "none", "title": "none", diff --git a/snippets/n_times_string.md b/snippets/n_times_string.md new file mode 100644 index 000000000..7dcf79791 --- /dev/null +++ b/snippets/n_times_string.md @@ -0,0 +1,18 @@ +--- +title: n_times_string +tags: string,beginner +--- + +Prints out the same string a defined number of times. + +Repeat the string `n` times, using the `*` operator. + +```py +def n_times_string(str,n): + return (str * n) +``` + +```py +n_times_string('py', 4) #'pypypypy' + +``` \ No newline at end of file