New to python and trying to figure out why the following 2 lists generate different output formats
n=5 mylist = "*" * n print(mylist) mylist = ["\*", "\*", "\*", "\*", "\*"] print(mylist) Output:
***** ['\*', '\*', '\*', '\*', '\*'] New to python and trying to figure out why the following 2 lists generate different output formats
n=5 mylist = "*" * n print(mylist) mylist = ["\*", "\*", "\*", "\*", "\*"] print(mylist) Output:
***** ['\*', '\*', '\*', '\*', '\*'] In Python when using a multiplication operator (*) with a string this string is repeated according to the number, for example
str = "-" * 6 # output : ------ NOTE : This operation returns a string and not a list
The second output is simply a list with elements and its output is as expected
I hope I have helped