Overview of Python
Explore fundamental Python programming concepts such as defining and using functions, handling variables and data types, applying basic arithmetic, and controlling code flow with conditional statements. This lesson provides hands-on coding challenges to reinforce your understanding of Python data representation and logic.
Functions
A function is a code block that takes in an input value or an argument and performs an action on it. Figure 1 shows a function that takes an argument, increments it by one, and returns it. In Python, there are two types of functions:
- Built-in functions are already defined in Python libraries, and we can call them directly.
The most common built-in function is the print function. It displays the input value on the console.
- User-defined functions are functions that we define ourselves in our program and then call them wherever we want.
The user defined function called increment is shown in the code snippet below. This function takes one argument, increments it by one and returns the resultant value.
Basic arithmetic operators
You can add two numbers and use the print function to visualize the output.
Likewise, you can use the four basic operators:
- add (+)
- subtract (-)
- multiply (*)
- divide (/)
and use the print function to visualize the output.
The order of ...