diff --git a/Notes/01_Introduction/01_Python.md b/Notes/01_Introduction/01_Python.md index 78778e0..214968b 100644 --- a/Notes/01_Introduction/01_Python.md +++ b/Notes/01_Introduction/01_Python.md @@ -2,8 +2,6 @@ In this part, we'll start with the absolute basics of Python. -## Reading - ### What is Python? Python is an interpreted high level programming language. It is often classified as a diff --git a/Notes/01_Introduction/02_Hello_world.md b/Notes/01_Introduction/02_Hello_world.md index 13c0180..a6070b0 100644 --- a/Notes/01_Introduction/02_Hello_world.md +++ b/Notes/01_Introduction/02_Hello_world.md @@ -3,8 +3,6 @@ This section discusses the creation of your first program, running the interpreter, and some basic debugging. -## Reading - ### Running Python Python programs run inside an interpreter. diff --git a/Notes/01_Introduction/04_Strings.md b/Notes/01_Introduction/04_Strings.md index 56713df..fd70da6 100644 --- a/Notes/01_Introduction/04_Strings.md +++ b/Notes/01_Introduction/04_Strings.md @@ -2,8 +2,6 @@ This section covers the basics of text manipulation. -## Reading - ### Representing Text String are text literals written in programs with quotes. @@ -28,6 +26,9 @@ Triple quotes capture all text enclosed in multiple lines. ### String escape codes +Escape codes are used to represent control characters and characters that can't be easily typed +at the keyboard. Here are some common escape codes: + ``` '\n' Line feed '\r' Carriage return @@ -36,7 +37,6 @@ Triple quotes capture all text enclosed in multiple lines. '\"' Literal double quote '\\'` Literal backslash ``` -These codes are inspired by C. ### String Representation @@ -45,9 +45,9 @@ Each character represents a raw unicode code point. ```python -a = '\xf1' # a = 'ñ' -b = '\u2200' # b = '∀' -c = '\U0001D122' # c = '𝄢' +a = '\xf1' # a = 'ñ' +b = '\u2200' # b = '∀' +c = '\U0001D122' # c = '𝄢' d = '\N{FORALL}' # d = '∀' ``` @@ -114,11 +114,13 @@ Replacing text. ```python s = 'Hello world' -t = s.replace('Hello' , 'Hallo') +t = s.replace('Hello' , 'Hallo') # 'Hallo world' ``` **More string methods:** +Strings have a wide variety of other methods for testing and manipulating the text data: + ```python s.endswith(suffix) # Check if string ends with suffix s.find(t) # First occurrence of t in s @@ -136,11 +138,11 @@ s.split([delim]) # Split string into list of substrings s.startswith(prefix) # Check if string starts with prefix s.strip() # Strip leading/trailing space s.upper() # Convert to upper case +``` ### String Mutability -Strings are "immutable". They are read only. - +Strings are "immutable" or read-only. Once created, the value can't be changed. ```python @@ -198,7 +200,7 @@ data = text.encode('utf-8') # text -> bytes ### Raw Strings -String with uninterpreted backslash. +Raw strings are strings with uninterpreted backslash. They are little by prefixing the initial quote with a lowercase "r". ```python >>> rs = r'c:\newdata\test' # Raw (uninterpreted backslash) @@ -206,12 +208,12 @@ String with uninterpreted backslash. 'c:\\newdata\\test' ``` -String is the literal text, exactly as typed. +The string is the literal text, exactly as typed. This is useful in situations where the backslash has special significance. Example: filename, regular expressions, etc. ### f-Strings -String with formatted expression substitution. +A string with formatted expression substitution. ```python >>> name = 'IBM' @@ -226,9 +228,9 @@ String with formatted expression substitution. >>> ``` -**Note: Requires Python 3.6 or newer.** +**Note: This requires Python 3.6 or newer.** -## Exercises 1.4 +## Exercises In this exercise, we experiment with operations on Python's string type. diff --git a/Notes/01_Introduction/05_Lists.md b/Notes/01_Introduction/05_Lists.md index a4b7c44..29e0c86 100644 --- a/Notes/01_Introduction/05_Lists.md +++ b/Notes/01_Introduction/05_Lists.md @@ -2,8 +2,6 @@ This section introduces lists, one of Python's basic objects for storing collections of data. -## Reading - ### Creating a List Use square brackets to create a list: @@ -156,7 +154,7 @@ s.sort() # ['bar', 'foo', 'spam'] Specifically, lists don't represent vectors/matrices as in MATLAB, Octave, IDL, etc. However, there are some packages to help you with that (e.g. numpy). -## Exercises 1.5 +## Exercises In this exercise, we experiment with Python's list datatype. In the last exercise, you worked with strings containing stock symbols. diff --git a/Notes/01_Introduction/06_Files.md b/Notes/01_Introduction/06_Files.md index bb44690..38ada14 100644 --- a/Notes/01_Introduction/06_Files.md +++ b/Notes/01_Introduction/06_Files.md @@ -2,8 +2,6 @@ This section discusses the basics of working with files. -## Reading - ### File Input and Output Open a file. @@ -81,7 +79,7 @@ with open('outfile', 'wt') as f: ... ``` -## Exercises 1.6 +## Exercises This exercise depends on a file `Data/portfolio.csv`. The file contains a list of lines with information on a portfolio of stocks. Locate the file and look at its contents: @@ -91,7 +89,7 @@ Locate the file and look at its contents: *Note: Make sure you are running Python in a location where you can access the `portfolio.csv` file. You can find out where Python thinks it's running by doing this: -```python +```pycon >>> import os >>> os.getcwd() '/Users/beazley/Desktop/practical-python' # Output vary diff --git a/Notes/01_Introduction/07_Functions.md b/Notes/01_Introduction/07_Functions.md index a966e89..c3711bd 100644 --- a/Notes/01_Introduction/07_Functions.md +++ b/Notes/01_Introduction/07_Functions.md @@ -3,8 +3,6 @@ As your programs start to get larger, you'll want to get organized. This section introduces functions. Error handling with exceptions is also introduced. -## Reading - ### Custom Functions Use functions for code you want to reuse. Here is a function definition: @@ -100,8 +98,7 @@ Traceback (most recent call last): RuntimeError: What a kerfuffle ``` - -## Exercises 1.7 +## Exercises ### (a) Defining a function diff --git a/_layouts/default.html b/_layouts/default.html new file mode 100644 index 0000000..e773aad --- /dev/null +++ b/_layouts/default.html @@ -0,0 +1,49 @@ + + +
+ + {% if site.google_analytics %} + + + {% endif %} + + +{% seo %} + + + + + + + Skip to the content. + +