User Tools

Site Tools


python

Overview

First pass at Python course topics.

Links:

… coming …

Packages

  • python3 (Python 3.7)
$ python3 -V
Python 3.7.4
$

Online tutorial

3

  • string operations
  • string slices

4

  • “else” clause on loop constructs
  • range() function is an “iterable”
  • keyword arguments
  • lambda expressions
  • docstrings
  • function annotation(???)

5 Data structures

  • lists
  • “import collections” (deque)
  • list comprehensions
  • set
  • dictionary
    • key can be any immutable type
    • “list(d)” returns list of keys
  • “enumerate()” routine for any sequence
  • “zip()” to iterate over two sequences simultaneously

TOPICS

  • string method join()
  • data types, numbers, literals
  • “_” as last value interactively
  • single and double quoted strings identical effectively
  • raw strings
  • “iterable” objects (“for” is an “iterator”)
    • list(range(1,10))
    • tuple(range(1,10))
  • loops and trailing “else” construct

STUFF

  • >>> quit()
  • PEP-8
  • function annotations

Basics

Arguments

import sys
print(sys.argv[0])

Printing

>>> print("hi")
>>> print("I am", age, "years old.")
>>> print(f"I am {age} years old.")     (format string)

>>> hilarious = False
>>> joke_evaluation = "Isn't that joke so funny?! {}"
>>> print(joke_evaluation.format(hilarious))
>>> print("Isn't that funny? {}".format(hilarious))

>>> print(end1 + end2 + end3 + end4 + end5 + end6, end=' ')
>>> print(end7 + end8 + end9 + end10 + end11 + end12)

>>> formatter = "{} {} {} {}"
>>> print(formatter.format(1, 2, 3, 4))
>>> print(formatter.format("one", "two", "three", "four"))

Strings

Raw strings: r“blah blah”

print("""\
Usage: thingy [OPTIONS]
     -h                        Display this usage message
     -H hostname               Hostname to connect to
""")
python.txt · Last modified: 2019/08/09 13:10 by rpjday