Fifth part of articles about the Microsoft's Python for Beginners series.
All the examples from the playlist are available in this GitHub repository: Python Examples.
Objective
You will learn how to create functions, importing modules and creating virtual environments.
A Python file was created to demonstrate each example.
Topics
function.py
Creating functions.
Executing the command below:
python .\examples\function.py
The result is:
module.py
Importing the "math_module.py".
Using its functions.
Executing the command below:
python .\examples\module.py
The result is:
venv.py
Create a virtual environment, install a package and use it in a module.
Execute the command below to create a folder called 'venv':
python -m venv venv
Press the 'Yes' button inside the popup that shows up inside the VSCode.
The virtual environment will be available in the project root folder.
Run the command below to use it:
.\venv\Scripts\Activate.ps1
The word '(venv)' will be visible in the left side of the current path.
And at the bottom of the VSCode, as well.
Create a file named 'requirements.txt' at the project root folder and type colorama inside of it.
Install the colorama package inside the venv with the following command:
pip install -r requirements.txt
The result will be:
Import colorama inside the math_module.py to write colored messages.
Finally, run the command below:
python .\examples\module.py
The result will be:
Next
You will learn how to make connect with web APIs, manipulate dictionaries, read environment variables and use decorators.
Video References
- Programming with Python | Python for Beginners [29 of 44]
- Programming with Python | Python for Beginners [30 of 44]
- Programming with Python | Python for Beginners [31 of 44]
- Programming with Python | Python for Beginners [32 of 44]
- Programming with Python | Python for Beginners [33 of 44]
- Programming with Python | Python for Beginners [34 of 44]
- Programming with Python | Python for Beginners [35 of 44]
Top comments (0)