Page 398 - Computer_Science_F5
P. 398

Alternatively, you can open the IDLE on Python and open  the HelloAfrica.py file to
              run it starting on the start bar with steps:
              In  search  field,  type  IDLEàopenàFileàopenàDesktopàPythonàHelloAf-
              ricaàRunàRun module.                                                                 Chapter Six: Object oriented programming with Python
          FOR ONLINE READING ONLY
              The output is shown in Figure 6.4:













                                   Figure 6.4: First Python program using IDLE



              Virtual environments                     (v)  Activate the virtual environment. On
              It is recommended to use virtual              Windows, run:
              environments to manage dependencies      (vi)  myenv\Scripts\activate
              and  isolate  project  environments.
              Virtual environments allow you to have   Once activated, any  Python packages
              separate Python installations and package   you install using pip will be installed
              dependencies for different projects. This   within the virtual environment, keeping
              helps avoid conflicts between different   them separate from your system-wide
              versions of packages used in different   Python installation.
              projects. To create a virtual environment,   Python fundamentals
              you can use tools like virtualenv or venv,
              which come bundled with Python. Here is   Python fundamentals involves defining
                                                       basic  syntax, variables,  operators,
              how you can create a virtual environment   expressions  and data types.
              using venv:
              (i)  Open a command prompt or terminal.  Basic syntax
              (ii)  Navigate to your project directory.  The  following    explain   important

              (iii) Run the following command to create  guideline for syntax in Python:
                   a virtual environment:
              (iv)  python-m venv myenv;  This         (a) Indentation
                   replace  myenv  with the name       In Python, indentation is used to signify
                   you want to give to your virtual    blocks of code. It is important to
                   environment.                        maintain consistent indentation, usually


                                                    389
               Student’s Book  Form Five



     Computer Science Form 5.indd   389                                                     23/07/2024   12:34
   393   394   395   396   397   398   399   400   401   402   403