Skip to content
This repository has been archived by the owner on Jul 13, 2021. It is now read-only.
/ learning-python Public archive

Introduction to the Python 3 Programming Language from egghead.io

License

Notifications You must be signed in to change notification settings

cujarrett/learning-python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

What is it?

It's a small set of hacks to learn the basics of Python. Python is powerful, fast, plays well with others, runs everywhere, is friendly & easy to learn, is Open. I'm using Python 3.7.5 for this project (current LTS).

Take Aways

  • Python comes on a lot of OS's by default but it's more common to find Python 2 instead of Python 3.

  • Python Virtual Environments allow you to specify a specific version of Python for that use. Requires first installing virtualenv via pip install virtualenv.

    Example creation of Python Virtual Environments

    # virtualenv <folder to create> <path to desired python version install>
    virtualenv py3 -p /usr/local/bin/python3

    Example activation of Python Virtual Environments

    # <folder created above via >/bin/activate
    py3/bin/activate

    Example deactivation of Python Virtual Environments

    deactivate
  • Python's package manager pip manages dependencies. It leverages a requirments.txt file detailing project dependencies.

    Example package install

    pip freeze > requirements.txt

    Example pip requirments.txt file

    cat requirements.txt
    certifi==2019.9.11
    chardet==3.0.4
    idna==2.8
    requests==2.22.0
    urllib3==1.25.7
  • pip install vs. import? pip install brings the dependency local for runtime where as import uses a looked up asset via putting it somewhere python can expect it to be.

  • In Python everything has a id. The id property is immutable.

  • In Python everything has a value.

  • Immutable vs. Mutable Types

    Class Description Immutable
    bool Boolean value
    int integer
    float floating-point number
    list mutable sequence of objects
    tuple immutable sequence of objects
    str character string
    set unordered set of distinct objects
    fronzenset immutable form of set class
    dict associative mapping (aka dictionary)
    b = []
    b(id) # 4527447816
    b.append(3)
    print(b) # [3]
    a = 4
    id(a) # 4321639424
    a = a + 1
    id(a) # 4321639456
  • Use None for null check in Python. Use a foo is None check for performance vs. slower and more process heavy foo == None as foo is None checks the id and it exits with less process needed.

  • Strings

  • String Manipulation

  • Conditionals

  • Loops

  • Relational Operators

  • Lists

  • List Slice

  • List Comprehensions

  • Dictionaries

  • Tuples

  • Sets

  • Logging

  • Command Line Input

  • Functions

  • Modules

  • Reading From A File

  • Writing To A File

  • Error Handling

  • Scopes

  • Classes

  • pip useful commands

    • pip install <package-name> to install a package
    • pip list to list all packages installed to the current virtual environment
    • pip search <package-name> can be used to search packages available
    • pip list --outdated show out of date dependencies
    • pip uninstall <package-name> to uninstall package

Things I like

  • Simple
  • Forces good styling as there is no braces used
  • Key word arguments
    def madlibs(name, noun = "shoes", adjective = "red"):
      return "{0} has {1} {2}".format(name, adjective, noun)
    madlib = madlibs("Will", adjective="black", noun="boots")
    print(madlib) # Will has black boots

Things I'm not a huge fan of

  • Python's package ecosystem doesn't seem to all use Semantic Versioning (example: idna as 2.8)
  • Text file for dependency details feels lackluster
  • Underscore as multi word variable convention (sum_of_two_numbers = 1 + 3) 😑
  • global, nonlocal, and local varibales are confusing solution that feels clumsier than just having scopes be blocked at first glance. I'm sure there's cool things you could do with it in principal, but I also feel like you'd be a jerk if you actually used them.

About

Introduction to the Python 3 Programming Language from egghead.io

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages