Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- __author__ = 'Work'
- '''
- Star unpacking combined with string processing operations, such as splitting.
- '''
- line = "nobody:*:-2:-2:Unprivileged User:/var/empty:/usr/bin/false"
- uname, *fields, homedir, sh = line.split(':')
- print('username: ', uname, '\n',
- 'homedir: ', homedir, '\n',
- 'sh: ', sh, '\n',
- 'fields: ', fields)
- '''
- Unpacking variables and throwing them away. Use a common throwaway variable name, such as _ or ign (ignored).
- Ex:
- '''
- record = [ 'ACME', 50, 123.45, (12, 18, 2012) ]
- name, *throwaway_0, (*throwaway_1, year) = record
- print(
- 'name: ', name, '\n',
- 'first throwaway variable: ', throwaway_0, '\n',
- 'second throwaway variable: ', throwaway_1, '\n',
- 'year:', year, '\n'
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement