Python Essentials include Configuration, Python Environments, Variables, Function, Conditionals, Loops, Arrays, and Objects.
Python Environments can be created and activated using the venv module.
Variables in Python can be assigned using the assignment operator (=).
Functions in Python can be defined using the def keyword.
C++ and Java constructor names are the same with their class names.
Constructor refers to a special function/method typically used to create/instantiate objects of classes.
Python defines the constructor using the __init__ method.
Instantiating objects in Python is done using the new operator.
__init__ refers to the constructor of the class.
Conditionals in Python can be expressed using if, elif, else.
Loops in Python can be implemented using for, while, and range.
Arrays in Python can be declared using the array() function.
Objects in Python can be created using the class keyword.
Looping in programming is almost always used because of the existence of arrays.
Unlike Java and C++, we do not create/define the class properties/attributes/variables in a Python class outside the constructor.
For loop using range and for loop using range are also used in Python.
Unlike Java and C++, Python does not require you to state the variable type, such as int, bool, String, char, etc.
A List can contains values, either homogenous or heterogeneous.
Inside the Dog class, you can see two methods, init and bark.
In Python, the keyword self is similar to “this” in Java, as it refers to the object/instantiated object.
Another method is to append a whole list to another list, as seen in the example below.
In Python, a collection created using square brackets is called a List.
You can use negative indexing to access the opposite side of the list (starting from the end)
One major difference here from other programming languages is the Python enables you to return multiple values, just separate them in a comma.
In Python, they are called modules, and you can download and integrate them in your project.
In Python, while loops and for loops are used.
Classes are the templates used to create objects, as they contain the properties/attributes and methods.
Use the command: Module name refers to the modules you want to add to your project.
Functions can have default arguments, meaning if you didn’t provide a value for that parameter, it will resort on using the default value set in the function definition.
Assigning and reassigning values in Python is done using the assignment operator =.
Adding items to a list in Python can be done in two methods: using the built-in function of the list called append, which can add one item on the end of the list.
Defining a function in Python requires the keyword def followed by the function name, a pair of parentheses that will contain the parameters passed on the function and a colon.
In Python, we don’t specify the type of value we are returning, as you’ve seen on the previous example.
Accessing each of the values inside the list/array becomes easier just because of loops.
Defining a function is not enough to use it, you need to call it, like methods/functions in Java and C++.