Last active
April 7, 2017 13:49
-
-
Save ekozlowski/08b423ebc7a66feffb53b7db69c712bf to your computer and use it in GitHub Desktop.
DFW Pythoneers Beginners Examples - 4/6/2017
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Functions! :) | |
def my_function_without_args(): | |
print("No args here!") | |
def my_function_with_args(first_argument, second_argument): | |
print(f"{first_argument} - {second_argument}") | |
def my_function_using_star_args(*args): | |
print(' '.join([x for x in args])) | |
def my_function_using_kwargs(**kwargs): | |
print(f"{kwargs.get('foo')} - {kwargs.get('bar')}") | |
def neat_trick(these='', args='', here=''): | |
print(f"{these} {args} {here}") | |
# Returns from functions! :) | |
def my_default_return(): | |
print("Hi") | |
if 1 == 1: | |
pass | |
else: | |
raise Exception(f"World ending... :(") | |
people = [] | |
class PersonNotFound(IndexError): | |
""" | |
Raised when a person is not found. :( | |
""" | |
def get_person(idx): | |
try: | |
print(1/0) | |
1/0 | |
except (IndexError, Exception) as e: | |
print(repr(e)) | |
if __name__ == "__main__": | |
get_person(2) | |
neat = {'these': 'ed', 'args': 'was', 'here': 'here'} | |
neat_trick(**neat) | |
my_function_without_args() | |
my_function_with_args("Ed", "Was Here") | |
my_function_using_star_args('ed', 'was', 'here') | |
my_function_using_kwargs(foo='ed', bar='wuz here') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You'll need to run this on Python 3.5 plus (because of the 'f' strings)