Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- >>65523359
- Yes, you understand how the multiple assignment statement works. You can use it on any iterable, not just strings. For instance:
- >>> [a, b] = [1, 2] # a = 1, b = 2
- >>> [a, b, c] = "abc" # a = "a", b = "b", c = "c"
- >>> [a, b, c] = range(1, 4) # a = 1, b = 2, c = 3
- >>> [a, b, c] = range(10)
- ValueError: too many values to unpack (expected 3)
- The above error is because there are not enough values on the left to map to the range on the right.
- You can use the star operator to assign the rest to one of the arguments.
- >>> [a, b, *c] = "ur mom gay" # a = "u", b = "r", c = " mom gay"
- Also, string.join(list) joins the list together with the string in between each list item and outputs the result. For instance:
- >>> " ".join(["G","E","N","T","O","O"]) # returns "G E N T O O"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement