Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions lesson_summary/python/REPL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
###Introducing the REPL for Rapid Experimentation
Comment thread
shankjs marked this conversation as resolved.

Python is an interpreted language, and the code is evaluated line-by-line.
Each line can be evaluated by itself, and this allows us to have a REPL.


What is a REPL?

>REPL stands for: Read, Evaluate, Print, Loop

>Each line is read, evaluated, the return value is then printed to the screen,
and then the process repeats.

>Python ships with a REPL, and you can access it by running python3.6 from your terminal.

Eg.1:
$ python3.6
Python 3.6.4 (default, Jan 5 2018, 20:24:27)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
Comment thread
shankjs marked this conversation as resolved.

Expln 1:
The >>> indicates that you can type on that line. Later on, you’ll also see a ... which
means that you are currently in a scoped area and will need to enter a blank line (no spaces)
before it evaluates the entire code block.

The simplest use of this would be to do some math:

Eg.2:
>>> 1 + 1
2
>>>

Expln 2:
2 is the return value of the expression, and it is then printed to the screen. If something
doesn’t have a return value, then nothing will be printed to the screen and you’ll see the
next prompt immediately. We’ll cover this later, but an example would be None:

Eg.3:
>>> None
>>>


Lastly, to exit the REPL, you can either type exit() (the parentheses are important), or you
can hit Ctrl+d on your keyboard.
37 changes: 37 additions & 0 deletions lesson_summary/python/comments.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
###Lesson Description - Using Comments
Comment thread
shankjs marked this conversation as resolved.

When writing scripts, we often want to leave ourselves notes or explanations.
Python (along with most scripting languages) uses the # character to signify
that the line should be ignored and not executed.



Single Line Comment

We can comment out a whole line:

Eg. 1 # This is a full like comment
Comment thread
shankjs marked this conversation as resolved.

or we can comment at the end of a line:

Eg. 2 2 + 2 # This will add the numbers





What About Block Comments?

Python does not have the concept of block commenting that you may have encountered
in other languages. Many people mistake a triple-quoted string as being a comment,
but it is not, it’s a multi-line string. That being said, multi-line strings can
functionally work like comments, but they will still be allocated into memory.

Eg. 3
"""
This is not a block comment,
but it will still work when you really need
for some lines of code to not execute.
"""
Comment thread
shankjs marked this conversation as resolved.