From da3aa14cee5ef4308f913bee54183b2e6f33d9dc Mon Sep 17 00:00:00 2001 From: weilun ong Date: Tue, 27 Apr 2021 09:29:08 +0800 Subject: [PATCH] addded lessson summary --- lesson_summary/python/REPL.md | 46 +++++++++++++++++++++++++++++++ lesson_summary/python/comments.md | 37 +++++++++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 lesson_summary/python/REPL.md create mode 100644 lesson_summary/python/comments.md diff --git a/lesson_summary/python/REPL.md b/lesson_summary/python/REPL.md new file mode 100644 index 0000000..e9d6fcb --- /dev/null +++ b/lesson_summary/python/REPL.md @@ -0,0 +1,46 @@ +###Introducing the REPL for Rapid Experimentation + +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. +>>> + +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. diff --git a/lesson_summary/python/comments.md b/lesson_summary/python/comments.md new file mode 100644 index 0000000..24a89bf --- /dev/null +++ b/lesson_summary/python/comments.md @@ -0,0 +1,37 @@ + ###Lesson Description - Using Comments + +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 + +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. +""" + +