{"assignment":{"_schema_version":2,"course_id":37,"date_created":"2022-06-28T19:00:00+00:00","date_modified":"2023-09-03T02:40:58.418781+00:00","extra_instructor_files":"","extra_starting_files":"","forked_id":null,"forked_version":null,"hidden":false,"id":976,"instructions":"## The Many Functions\n\n- **`abs`:** Calculate the absolute value of a number\n- **`bool`:** Convert a value to a Boolean\n- **`int`:** Convert a value to an integer\n- **`pow`:** Raise a number to the power of another number\n- **`len`:** Determine the length of a string\n- and many others...\n\nPython has many, many built-in functions.\nYou could never learn them all in this course.\nYou will learn a few, but it's far more important that you learn _how to learn_ more about functions.\n\n## Learning about a Function\n\n![Documentation of the built-in `len` function.](functions_builtin_docs.png)\n\nGood programmers create documentation for their functions.\nDocumentation is extra information about a function that makes it clear how it works.\nThere are many ways to write documentation, but they usually have a few things in common.\n\n## Function Documentation\n\n![The same text from the previous slide with the following words circled: Name, Parameters, Return value, Description, Examples.](functions_builtin_docs_highlighted.png)\n\nYou should look for six major parts:\nThe function's name, the syntax of its call, its parameters, its return value, its description, and examples of how to use the function\n\nSometimes, documentation will only include some of this information, so you must get used to inferring the missing details from context.\n\n## Parameters and Arguments\n\n![A line of code is shown, with its documentation below. Annotations indicate that the `3` and `10` are arguments, while `length` and `width` are parameters.](functions_builtin_args_params.png)\n\nWhen we use a function, we provide specific information called _arguments_.\nThese arguments are like data that the function works with.\nTo make it easier to refer to these data values inside the function, we use _parameters_.\nParameters act as formal names for the arguments.\nFor instance, in the example shown, the arguments are `3` and `10`.\nThe documentation states that these values correspond to the parameters `length` and `width`.\n\n#### Nesting Function Calls\n\n![Arrows point from the value `\"Hello World\"` to the function name `len`, and then arrows point from `len` to the function name `print`.](functions_builtin_nested_function_calls.png)\n\nA common task is to nest function calls inside of other function calls.\nWhen nesting function calls, you read from the inside outward.\nThis can be a little unintuitive, but it may help to treat the parentheses the same you would in a math operation.\nHowever, it's critical to remember that the parentheses are there because they are what call the function\u2014not because they are doing math.\n\n#### Chaining Methods\n\n![Arrows point from the value \"hello world\" to the method name `title`, and then arrows point from `title` to the method name `count`.](functions_builtin_chained_methods.png)\n\nWhen you need to call methods on the same string variable or value, it's a little different.\nAs described in the following diagram, you will repeat the period, name, and parentheses each time.\nBy placing them side by side, you will keep using the same variable, modifying it in turn from left to right.\n\n#### Functions, Methods, and Operators\n\n![Some code is shown with annotations. The `string_length =` is labelled as an assignment statement. The `len(` part is labelled as a function call. The `+` part is labelled as a string addition. The `.strip()` is labelled as a method call.](functions_builtin_labeled_parts.png)\n\nSince calls are just another expression, you can freely combine them with each other.\nIn the example code shown, we combine string addition, a string method call, and a function.\nThink about the order of execution; this can be tricky to follow.\nThe order of operations here is that the method call will occur first, removing the space characters from around the `\" world \"` string literal value.\nThen, the two string literals will be added together.\nFinally, the outer function call will be executed with the `\"hello world\"` value; this counts the number of characters in the string, which is the value `11`.\nNote that the value `11` and the value `\"hello world\"` are not in the code anywhere \u2014 these values are computed at runtime.\n\n#### Input/Output\n\n- **`print`:** Consumes any number of arguments, outputs them on the console, and returns None.\n- **`input`:** Consumes a single string, takes user input, and returns the user's input string.\n\nYou already know two functions: `print` is a function that takes in arguments and writes to the console.\n`input` is a function that reads from the console and returns it as a string value.\nThese two functions are strange because they have side effects.\nThe `input` function puts a textbox on the console, and the print function writes text to the console.\nGoing forward, we will use these two functions a lot less than we did up until now, although they will have their purpose.\n\n#### int, float, str, bool\n\n- **`str`:** Converts an argument to a string value.\n- **`int`:** Converts an argument to an integer value.\n- **`float`:** Converts an argument to a float value.\n- **`bool`:** Converts an argument to a Boolean value.\n\nFour other functions that are useful to know are `int`, `float`, `str`, and `bool`.\nThese four functions are used for type conversion or type casting values.\nThey can consume one value of any type and convert that value to the new type.\n\n#### int and float\n\n```python int-float-example\n# int: Consumes anything, returns an integer (if possible)\nprint(int(\"27\"))\n\n# float: Consumes anything, returns a float (if possible)\nprint(float(\"29.4\"))\n\n# This will fail with an error!\nprint(int(\"two\"))\n```\n\nFor integers and floats, this requires the value to make sense \u2014 _you can convert strings of digits but not strings with letters_.\nThose values will cause an error if you attempt to convert them.\n\n#### str\n\n```python str-example\n# str: Consumes anything, returns a string (always possible)\nprint(str(27)  + \" is a string now and can be safely added!\")\nprint(str(True))\n```\n\nThe str function, however, allows you to convert ANYTHING to a string.\nUsing the str function is particularly important since we cannot add values of different types; if we want to use values of other types in a string, we must convert the values first.\n\n#### bool\n\n```python bool-example\n# bool: Consumes anything, returns a Boolean (always possible)\nprint(bool(\"Hello World\"))\nprint(bool(\"\"))\n```\n\nSimilarly, the bool function also allows you to convert anything to a Boolean value.\nWe'll discuss the rules for how values get converted in the next chapter, but for now you just need to know that everything can be converted to a string or Boolean.\n\n#### Summary\n\n- Python has many built-in functions available for you to use.\n- Function documentation explains how to use a new function by explaining the function's purpose and details.\n- Function documentation usually also includes the name of the function, the names and purpose of the function's parameters, the type and description of the function's return value, and examples of how the function works in practice.\n- Parameters are the formal names used to describe the arguments.\n- Function calls can be nested inside of each other; you evaluate their arguments before the call itself \u2014 so they are evaluated \"inside out\" relative to each other instead of \"left to right.\"\n- Method calls can be chained together one after the other; method calls are evaluated left to right, with the new value being passed between as an argument to the next method.\n- Function and method calls can be arbitrarily nested along with other operations.\n- The basic conversion functions are:\n  - `str`: Converts an argument to a string value\n  - `int`: Converts an argument to an integer value\n  - `float`: Converts an argument to a float value\n  - `bool`: Converts an argument to a Boolean value\n- The basic functions for interacting with the terminal are:\n  - `print`: Consumes any number of arguments, outputs them on the console, and returns None.\n  - `input`: Consumes a single string, takes user input, and returns the user's input string.\n\n","ip_ranges":"","name":"2A2) Built-in Functions Reading","on_change":"","on_eval":"","on_run":"","owner_id":1,"owner_id__email":"acbart@udel.edu","points":0,"public":true,"reviewed":false,"sample_submissions":[],"settings":"{\n  \"header\": \"Builtin Functions\",\n  \"slides\": \"bakery_functions_builtins.pdf\",\n  \"youtube\": {\n    \"Bart\": \"SOt_NuIjxz0\",\n    \"Amy\": \"Ri7eXDy9ZFo\"\n  },\n  \"video\": {\n    \"Bart\": \"https://blockpy.cis.udel.edu/videos/bakery_functions_builtins-Bart.mp4\",\n    \"Amy\": \"https://blockpy.cis.udel.edu/videos/bakery_functions_builtins-Amy.mp4\"\n  },\n  \"summary\": \"In this lesson, you'll learn more about calling functions and methods. In particular, you will learn how to read documentation about built-in functions that you can use. You will also learn how to nest, chain, and combine functions and methods.\",\n  \"small_layout\": true\n}","starting_code":"","subordinate":true,"tags":[],"type":"reading","url":"bakery_functions_builtins_read","version":8},"ip":"216.73.216.157","submission":{"_schema_version":3,"assignment_id":976,"assignment_version":8,"attempts":0,"code":"","correct":false,"course_id":37,"date_created":"2026-05-20T16:04:53.447118+00:00","date_due":"","date_graded":"","date_locked":"","date_modified":"2026-05-20T16:04:53.447118+00:00","date_started":"","date_submitted":"","endpoint":"","extra_files":"","feedback":"","grading_status":"NotReady","id":2037054,"score":0.0,"submission_status":"Started","time_limit":"","url":"submission_url-4fba551d-75b7-4520-b8b4-13359ee6daf9","user_id":2044700,"user_id__email":"","version":0},"success":true}
