Skip to content

Latest commit

 

History

History
168 lines (103 loc) · 5.25 KB

File metadata and controls

168 lines (103 loc) · 5.25 KB

Week 1: Environment Setup and Introduction

Downloading Python

Python comes pre-installed on Linux OS. For Windows you will have to Download. Download Python here

Resources

Python For Beginnes

Text Editors

Use a text-editor of your choice:

Recommended are:

Visual Studio Code Atom Sublime Text

Git and GitHub Setup.

Note that you have to pass the challenges in git and github to proceed to the next stages. They are essential tools in development for code sharing and collaboration.

Get Started Here

Raise an Issue if encountering a blocker

Practice Code

  1. Print
  2. Variables
  3. Dates
  4. Error Handling
  5. Conditions
  1. Print

    The print function allows you to send output to the terminal

    Strings can be enclosed in single quotes or double quotes

    • "this is a string"
    • 'this is also a string'

    The input function allows you to prompt a user for a value

    Parameters:

    • prompt: Message to display to the user

    return value:

    • string value containing value entered by user
  2. Variables: Numeric

    Python can store and manipulate numbers. Python has two types of numeric values: integers (whole numbers) or float (numbers with decimal places)

    When naming variables follow the PEP-8 Style Guide for Python Code

    Converting to numeric values

  3. Variables: String

    Python can store and manipulate strings. Strings can be enclosed in single or double quotes. There are a number of string methods you can use to manipulate and work with strings

    Converting to string values

    When naming variables follow the PEP-8 Style Guide for Python Code

  4. Dates

    The datetime module contains a number of classes for manipulating dates and times.

    Date and time types:

    • date stores year, month, and day
    • time stores hour, minute, and second
    • datetime stores year, month, day, hour, minute, and second
    • timedelta a duration of time between two dates, times, or datetimes

    When naming variables follow the PEP-8 Style Guide for Python Code

    Converting from string to datetime

  5. Error Handling

    Error handling in Python is managed through the use of try/except/finally

    Python has numerous built-in exceptions. When creating except blocks, they need to be created from most specific to most generic according to the hierarchy.

  6. Conditions

    Conditional execution can be completed using the if statement

    if syntax

    if expression:
       # code to execute
    else:
       # code to execute

    Comparison operators

    • < less than
    • < greater than
    • == is equal to
    • >= greater than or equal to
    • <= less than or equal to
    • != not equal to
  7. Multiple Conditions

    Conditional execution can be completed using the if statement. Adding elif allows you to check multiple conditions

    if syntax

    if expression:
       # code to execute
    elif expression:
       # code to execute
    else:
       # code to execute

    Boolean operators

    • x or y - If either x OR y is true, the expression is executed

    Comparison operators

    • < less than
    • < greater than
    • == is equal to
    • >= greater than or equal to
    • <= less than or equal to
    • != not equal to
    • x in [a,b,c] Does x match the value of a, b, or c