Computer Science
How does '*' operator behave on strings?
Python String Manipulation
3 Likes
Answer
The * operator creates a new string by repeating multiple copies of the same string.
For example,
string = "abc"
repeated_string = string * 3
print(repeated_string)
Output
abcabcabc
In the above example, the string "abc" is repeated 3 times to produce "abcabcabc".
Answered By
1 Like
Related Questions
Assertion (A): Indexing in a string is defined as positive and negative indexing.
Reasoning (R): In forward and backward indexing, the indices start with 1st index.
- Both A and R are true and R is the correct explanation of A.
- Both A and R are true but R is not the correct explanation of A.
- A is true but R is false.
- A is false but R is true.
Assertion (A): The following code snippet on execution shall return the output as: False True
str1 "Mission 999" str2 = "999" print(str1.isdigit(), str2.isdigit())Reasoning (R): isdigit() function checks for the presence of all the digits in an inputted string.
- Both A and R are true and R is the correct explanation of A.
- Both A and R are true but R is not the correct explanation of A.
- A is true but R is false.
- A is false but R is true.
Explain function split() with an example.
How many times is the word 'HELLO' printed in the following statement?
s = "python rocks" for ch in s: print ("Hello")