- 1

Raising a string to a power?

Hey everyone, I was wondering if it's possible to raise a string to a power. I've tried spam**2 in the console but have ended up with this error Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: unsupported operand type(s) for ** or pow(): 'str' and 'int' Any tips?

6th Apr 2016, 1:49 AM
Jarryn McMaster
Jarryn McMaster - avatar
4 Antworten
+ 3
No, you cannot raise a string by a number but you can: - add strings: "abc" + "def" results in "abcdef" - multiply string by a number: "abc" * 3 gives "abcabcabc" Note: From the definiton of the multiplication above power does not make sense as it would require multiplication of a string by a string to be defined.
25th Jun 2016, 7:45 AM
Václav Brožík
Václav Brožík - avatar
+ 1
I do not think that is possible. Also, what result would you expect from raising a string to a power? :)
23rd May 2016, 10:27 AM
James Flanders
+ 1
That is not possible
30th Jul 2016, 5:48 AM
Narek Tonoyan
Narek Tonoyan - avatar
0
Well, if you expected to print spam twice by giving that a shot.... the correct way is to use loops :)
24th Jun 2016, 8:48 PM
Swagata
Swagata - avatar