Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Unpacking with tuples
- job_opening = ("Software Engineer", "New York City", 100000)
- position, city, salary = job_opening
- print(position)
- print(city)
- print(salary)
- # Using asterisk with tuples
- address = ("35 Elm Street", "San Francisco", "CA", "94107")
- street, *city_and_state, zip_code = address
- print(street)
- print(zip_code)
- print(city_and_state)
- # This is a function that returns the sum of all the even numbers on the left side
- # and the sum of all the odd numbers of a tuples
- def sum_of_evens_and_odds(*numbers):
- sum_evens = 0
- sum_odds = 0
- for number in numbers:
- if number % 2 == 0:
- sum_evens += number
- else:
- sum_odds += number
- return(sum_evens, sum_odds)
- print(sum_of_evens_and_odds(1, 2, 3, 4))
- print(sum_of_evens_and_odds(1, 3, 5))
- print(sum_of_evens_and_odds(2, 4, 6))
- Software Engineer
- # New York City
- # 100000
- # 35 Elm Street
- # 94107
- # ['San Francisco', 'CA']
- # (6, 4)
- # (0, 9)
- # (12, 0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement