Overview of Python

This lesson will give you an overview of Python.

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.
Figure 1. Functions that increment the given value.

The most common built-in function is the print function. It displays the input value on the console.

Press + to interact
print(5)
  • 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.

Press + to interact
def increment(n):
return n+1
result = increment(5)
print(result)

Basic arithmetic operators

You can add two numbers and use the print function to visualize the output.

Press + to interact
print(5 + 5)

Likewise, you can use the four basic operators:

  • add (+)
  • subtract (-)
  • multiply (*)
  • divide (/)

and use the ...

Access this course and 1400+ top-rated courses and projects.