Читать книгу Introduction to Python Programming for Business and Social Science Applications - Frederick Kaefer - Страница 67
Chapter Summary
ОглавлениеThis chapter introduced the building blocks of Python programming, including Python data types, coding statements, and functions. We first learned about some practices to follow when developing code, which becomes very important when you work with other people on programming projects. We next learned about basic elements of Python code, including Python keywords, objects and classes, variables and data types, and operators and delimiters, which are combined into various statements that make up Python code.
We then learned about how to use variables in assignment statements, using print statements to visualize our results. We also learned how to use the Python type function to determine and report the data type of an object in a Python program and why the order of operations is important when we have Python code that performs calculations. We also learned there are three types of errors in Python: syntax errors, exceptions, and logic errors. Syntax errors are the easiest types of errors to resolve and result when we do not follow the rules for correctly specifying Python code. Exceptions are the types of errors that occur when we attempt to do something in Python that is not possible or not allowed. Logic errors occur when code executes without terminating with an error message but has incorrect results.
We also learned about a few functions that Python already has defined and that one common use of built-in functions is converting object data types from one type to another. Next we learned about user-defined functions and how functions can have arguments (values passed to them) as well as return values. We saw how we must be careful when specifying arguments when we call functions or else errors will result. Next, we learned about how we can import Python code from different modules of code so our code can use their functions. As we will see throughout the book, this is an important mechanism for using Python code that is in packages.
In the next chapter, we will delve deeper into compound data types, including lists, tuples, and dictionaries. We will see how useful these are when working with data and develop an even deeper understanding of the capabilities of the Python programming language. We will also discuss techniques for handling exceptions and resolving logic errors in our code.