Welcome to this introductory programming course based on the Python programming language.
- Variables
- Conditions
- Chained Conditionals
- Operators
- Control Flow
- Loops and Iterables
- Basic Data Structures
- Functions
- Mutable vs. Immutable
- Common Methods
- File IO
- Object Oriented Programming
- Data Structures
- Comprehensions
- Lambda Functions
- Map, Filter
- Collections
- *args & **kwargs
- Inheritance
- Dunder Methods
- PIP
- Environments
- Modules
- Async IO
- Decorators
- Generators
- Context Managers
- Metaclasses
- Concurrency
- Parallelism
- Testing
- Packages
x = iter([1, 2, 3])
>>> x
<listiterator object at 0x1004ca850>
>>> next(x)
1
>>> next(x)
2
>>> next(x)
3
>>> next(x)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
StopIteration
class Range:
def __init__(self, n):
self.i = 0
self.n = n
def __iter__(self):
return self
def __next__(self):
if self.i < self.n:
i = self.i
self.i += 1
return i
else:
raise StopIteration()
class ReverseRange:
def __init__(self, count):
self.i = count
self.count = count
def __iter__(self):
return self
def __next__(self):
if self.i > 0:
i = self.i
self.i -= 1
return i
else:
raise StopIteration()
def yrange(n):
i = 0
while i < n:
yield i
i += 1
def even_generator(numbers):
for number in numbers:
if number % 2 == 0:
yield int(number)
my_gen = (<expression> for <item> in <iterable> if <condition>)
eg = (int(number) for number in my_list if number % 2 == 0)
my_list = [<expression> for <item> in <iterable> if <condition>]
squares = [i * i for i in range(10)]
my_dict = {<key>:<value> for <item> in <iterable> if <condition>}
dict1 = {'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5}
# Double each value in the dictionary
double_dict1 = {k:v*2 for (k,v) in dict1.items()}
my_set = {<expression> for <item> in <iterable> if <condition>}
>>> {s for s in [1, 2, 1, 0]}
set([0, 1, 2])
>>> {s**2 for s in [1, 2, 1, 0]}
set([0, 1, 4])
>>> {s**2 for s in range(10)}
set([0, 1, 4, 9, 16, 25, 36, 49, 64, 81])
- Empty lists
[]
- Empty tuples
()
- Empty dictionaries
{}
- Empty sets
set()
- Empty strings
""
- Empty ranges
range(0)
- Zero of any numeric type
- Integer:
0
- Float:
0.0
- Complex:
0j
None
False
By default, an object is considered true.
- Non-empty sequences or collections (lists, tuples, strings, dictionaries, sets).
- Numeric values that are not zero.
True
- Structural pattern matching in Python 3.10
- Time complexity in CPython
- Pass by reference in Python
- Variables in Python
- Variables and scope - Global, nonlocal and local
- Truthy and Falsy in Python
- What every programmer needs to know about encodings
- How Python does Unicode
- Dictionary comprehension tutorial
- How to use Python lambda functions
- Destructuring in Python
- Listening to sorting algorithms
- Tkinter 8.5 reference
- Iterators and generators
- Four types of comprehensions
- When to use a list comprehension
- Context managers and Python's
with
statement - Primer on Python decorators
- Introduction to Python generators