Getting started with
Python
Comments in Python
     • A comment is a line or part of a line that will be ignored by Python.
     • A comment in Python begins with one or more # symbols. Everything that follows this symbol
        to the end of the line is considered a comment.
          You can create a whole line of comments or at the end of a line of code
                                                                                                    49
Packages in Python
  • Python Packages are a way to organize and structure your Python code into reusable components. Think of
    it like a folder that contains related Python files (modules) that work together to provide certain
    functionality.
  • Packages help keep your code organized, make it easier to manage and maintain, and allow you to share
    your code with others.
   Example :
     • NumPy
     • Pandas
     • SciPy
     • Bio
                                                                                                          50
Packages in Python
  • To install a new package:           pip install package_name
  • Some packages are loaded automatically when you start Python, such as the base subdirectory. To load the
     package into memory:
  Import package_name
  # Use functions or classes from the package
  result = package_name.some_function()
                                                                                                       51
Algorithm, Function and
        Variable
Variable
   A variable is like a box with a name (or identifier) that contains a value (variable content).
   Example:
              variable Age, which corresponds to a person's age.
              Variable: name = "x" and value = 20                                           Memory
                                                                                                20
                                                                                                    X
   Python code:
              x = 20
   Explanation:
   The = operator is called the assignment operator. It takes any value on the right and places it in the variable
   indicated on the left. The command might read "put the value 20 in the variable named x".
                                                                                                              53
Variable
   Naming variables in R :
   • Allowed characters for variable names are lowercase letters a-z and uppercase letters A-Z, numbers 0-9
       and the underscore character "_".
   • They may not begin with a number (2x is not valid, but x2 is).
   • Python is case-sensitive, meaning foo, Foo and FOO are three distinct variables.
   • Certain names are used by the Python system, so it's best to avoid using them. In particular, avoid using
       c, q, t, C, D, I, diff, len, mean, pi, range, var. Some words are reserved and may not be used. Words
       reserved for the system are: break, else, for, function, if, in, next, repeat, return, while, TRUE, FALSE, Inf,
       NA, NaN, NULL, NA_integer_, NA_real_, NA_complex_, NA_character_
   • It's also best to avoid dots ( .) in a variable name, as in my.object.
   • The name cannot use special symbols such as ^, !, $, @, +, -, /, or *.
                                                                                                                  54
Variable
   • Python will overwrite any previous information stored in a variable without asking your permission. It is
      therefore advisable not to use names that have already been taken.
   • To view variable names already in use, use the environment panel.
                                                                                                          55
Algorithm
                             Algorithm => sequence of instructions for solving a problem.
          Example: Reconstructing a PUZZLE ( puzzle pieces + followed by instructions / processing + Result )
                     INPUT                              ALGORITHM                       OUTPUT
                                        INPUT           FUNCTION     OUTPUT
                     FUNCTION     OUTPUT                                     INPUT           FUNCTION     OUTPUT
  INPUT                                            Sub-algorithm
                                                                                                                   56
Function
    • Sub-algorithm => division into several smaller parts called FUNCTION.
    • A Function is a sequence of instructions grouped under a name. It takes parameters as input (INPUT)
       and returns a result (OUTPUT).
                          INPUT                   FUNCTION        OUTPUT
                    Argument / parameter
                                                                                                       57
Function
    1. Function declaration                         2.   Calling or using the Function
    • Provide the name of the function              • Use the result in a process
    • Define the inputs or arguments                • Display the result
    • Write the processing ( which will use these   • Put the result in a variable
       arguments to give a result)
    • Return the result found
                                                    Syntaxe en Python:
    Syntaxe en python :                             Function_name(arg1, arg2, arg3)
    def function_name(arg_1, arg_2, arg_3) :
      # instructions
      return
                                                                                         58
Function
      Example: Example: Function for calculating the square of a number.
      1. Define the arguments or inputs
      2. Write the processing
      3. Return the result
                                                                                       Output :
                                                Input :Nbr                 Nbr * Nbr   Result of
                                                                                       multiplication
      def carre (x):
        return x*x
      carre(2)
                                                                                              59