- Entering expressions into the interactive shell
- The integer, floating-point, and string data types
- String concatenation and replication
- Storing values in variables
- Assignment statements
- Variable names
- Your first program
- Dissecting your program
- Comments
- The
print() function
- The
input() function
- Printing the user’s name
- The
len() function
- The
str(), int(), and float() functions
- Working with Strings
- String literals
- Double quotes
- Escape characters
- Raw strings
- Multiline strings with triple quotes
- Multiline comments
- Indexing and slicing strings
- The
in and not in operators with Strings
- Putting strings inside other strings
- String interpolation
- f-strings
- Useful String methods
upper(), lower(), isupper(), and islower() methods
- The
isX() methods: isalpha(), isalnum(), isdecimal(), isspace(), istitle()
- The
startswith() and endswith() methods
- The
join() and split() methods
- Splitting strings with the
partition() method
- Justifying text with the
rjust(), ljust(), and center() methods
- Removing whitespace with the
strip(), rstrip(), and lstrip() methods
- Numeric values of characters with the
ord() and chr() functions
def statements with parameters
- Define, call, pass, argument, parameter
- Return values and return statements
- The
None value
- Keyword arguments and the
print() function
- The call stack
- Local and global scope
- Local variables cannot be used in the global scope
- Local scopes cannot use variables in other local scopes
- Global variables can be read from a local scope
- Local and global variables with the same name
- The global statement
- Boolean values
- Comparison operators
- Boolean operators
- Binary boolean operators
- The not operator
- Mixing Boolean and comparison operators
- Elements of flow control
- Conditions
- Blocks of code
- Program execution
- Flow control statements
if statements
else statements
elif statements
- While loop statements
- Break statements
- Continue statements
- For loops and the
range() function
- An equivalent while loop
- The starting, stopping, and stepping arguments to
range()
- Importing modules
- Ending a program early with the
sys.exit() function
Data Structures
- The list data type
- Getting individual values in a list with indexes
- Negative indexes
- Getting a list from another list with slices
- Getting a list’s length with the
len() function
- Changing values in a list with indexes
- List concatenation and list replication
- Removing values from lists with
del statements
- Working with lists
- Using
for loops with lists
- The
in and not in operators
- The multiple assignment trick
- Using the
enumerate() function with lists
- Using the
random.choice() and random.shuffle() functions with lists
- Augmented assignment operators
- Methods
- Finding a value in a list with the
index() method
- Adding values to lists with the
append() and insert() methods
- Removing values from lists with the
remove() method
- Sorting the values in a list with the
sort() method
- Reversing the values in a list with the
reverse() method
- Sequence data types
- Mutable and immutable data types
- The tuple data type
- Converting types with the
list() and tuple() functions
- References
- Identity and the
id() function
- Passing references
- The copy module’s
copy() and deepcopy() functions
- The
dict data type
- Dictionaries vs. lists
- The
keys(), values(), and items() methods
- Checking whether a key or value exists in a dictionary
- The
get() method
- The
setdefault() method
- Pretty printing (
pprint module)
- Using data structures to model real-world things
- The
set data structure
- Creating a set
- Set operations
- The
collections module
- Named tuple
- Default dictionary
- Counter
- The deque
File Handling
- Reading and Writing Files
- Files and file paths
- Backslash (
\) on Windows and forward slash (/) on macOs and Linux
- Using the
/ operator to join paths
- The current working directory
- The home directory
- Absolute vs. relative paths
- Creating new folders using the
os.makedirs() function
- Handling absolute and relative paths
- Getting the parts of a file path
- Finding file sizes and folder contents
Modifying a list of files using glob patterns
(Interested? See pattern matching with Regex)
- Checking path validity
- The file reading/writing process
- Opening files with the
open() function
- Reading the contents of files
- Writing to files
- Organizing Files
- The
shutil module
- Copying files and folders
- Moving and renaming files and folders
- Permanently deleting files and folders
- Walking a directory tree
- Error handling.
- Raising exceptions
- Getting the traceback as a string
- Assertions
- Logging
- Using the logging module
- Don’t debug with the
print() function
- Logging levels
- Disabling logging
- Logging to a file
- Debugging in VSCode
- Classes and objects
- Accessing object variables
- Accessing object functions
init() function