three levels of nesting you should probably start to question your data structure design it' important to distinguish the above syntax from list comprehension inside list comprehensionwhich is also perfectly validin [ ][[ for in tupfor tup in some_tuplesfunctions functions are the primary and most important method of code organization and reuse in python there may not be such thing as having too many functions in facti would argue that most programmers doing data analysis don' write enough functionsas you have likely inferred from prior examplesfunctions are declared using the def keyword and returned from using the return keyworddef my_function(xyz= )if return ( yelsereturn ( ythere is no issue with having multiple return statements if the end of function is reached without encountering return statementnone is returned each function can have some number of positional arguments and some number of keyword arguments keyword arguments are most commonly used to specify default values or optional arguments in the above functionx and are positional arguments while is keyword argument this means that it can be called in either of these equivalent waysmy_function( = my_function( the main restriction on function arguments it that the keyword arguments must follow the positional arguments (if anyyou can specify keyword arguments in any orderthis frees you from having to remember which order the function arguments were specified in and only what their names are namespacesscopeand local functions functions can access variables in two different scopesglobal and local an alternate and more descriptive name describing variable scope in python is namespace any variables that are assigned within function by default are assigned to the local namespace the local namespace is created when the function is called and immediately populated by the function' arguments after the function is finishedthe local namespace is destroyed (with some exceptionssee section on closures belowconsider the following function appendixpython language essentials www it-ebooks info