Advertisement
Guest User

Untitled

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