>>>”

The general format is: string * n Where n is a number of type int. Using the * operator repeats the string n number of times. For example: >>> >>> s = "www " * 5 # repeat "www " 5 times >>> s 'www www www www www ' >>> >>> >>> >>> print("We have got some", "spam" * 5) We have got some spamspamspamspamspam >>> Note that 5 * "www " and "www " * 5 yields the same result. Python can’t multiply strings by non-int data types and will show an error if you use a different data type for n. For example: Traceback (most recent call last): File "", line 1, in TypeError: can't multiply sequence by non-int of type 'str' >>> >>> >>> "www" * 1.5 # n is a float Traceback (most recent call last): File "", line 1, in TypeError: can't multiply sequence by non-int of type 'float' >>>

9. Use slicing operators [start_index:end_index] to get a slice of a string.

str_name[start_index:end_index] str_name[start_index:end_index] would return a slice of string starting from index start_index to end_index. The character at the end_index location is not included in the slice. For example: >>> >>> s = "markdown" >>> >>> >>> s[0:3] # returns a string slice starting from index 0 to 3, not including the character at index 3 'mar' >>> >>> >>> s[2:5] # returns a string slice starting from index 2 to 5, not including the character at index 5 'rkd' >>> If end_index is greater than the length of the string, then the slice operator would return a string slice starting from start_index to the end of the string. >>> >>> s[2:len(s)+200] 'rkdown' >>> start_index and end_index are optional. If start_index is not specified, then slicing will begin at the beginning of the string. If end_index is not specified, then it goes on to the end of the string. For example: >>> >>> s[:4] # start slicing from the beginning 'mark' >>> In the above expression, the slicing begins at the beginning of the string, so the above expression is the same as s[0:4]. >>> >>> s[5:] 'own' >>>