Thanks for sharing your feedback! If your feedback doesn't appear right away, please be patient as it may take a few minutes to publish - or longer if the blogger is moderating comments.

Fundamentals of Python: Functions, Formatting & Assignment Statements (Week 2)

Here we are at Week 2 of Fundamentals of Python! This week covered Functions, Formatting & Assignment statements, which don't need much explanation really, so let's get right into it!

If you need access to Week 1, here it is!

Lesson 1: Visualizing Assignment Statements

The most important note in this lesson is understanding that assignment of variables does not mean that a variable is *equal* to the value or function it is assigned to represent.

Here are the rules for Executing an Assignment Statement:

  1. Evaluate the expression on the right side of the equals sign to produce a value. This value also has a memory address. This value also has a memory address.
  2. This memory address will be stored in the right side of the = sign, with the variable who is referencing it remaining on the left side.

REMEMBER! Assignment changes the value of a VARIABLE, not what is stored in the memory address!

Additional Notes from this Lesson:

-          In IDLE, you can access the visualizer tool by navigating through Explore > Visualize to see the state of computer memory used during the execution of your code.

Lesson 2: typ str

typ str is Python’s representation of the String type. In order to define a string literal, which is a sequence of characters, it must begin and end with either ‘ or “. Additionally, string literals can be assigned to variables. It is important to note that if your string literal needs to include a contraction or possessive, you can use “s to define them. Additionally, you have the option of using \’ to refer to your ‘ in the string, and using ‘s to define it completely.

Strings also are able to be concatenated using the + operator, but you have to remember to include spaces where appropriate, as the + operator simply mashes the strings together and does not take any spacing into account. Additionally, you can use the * operator on strings to replicate a string any number of times. However, it’s important to note that order of operations still applies when using these “mathematical operators” on your strings. And before you go running off to try / and -, no, those operators don’t work and will only result in you achieving a TypeError.

Lesson 3: Input/Output & str Formatting

In order to print by passing a single function to argument call, you’ll want to produce a statement something to the effect of this:

Print (“text”) => text

Print(3+7-3) => 7

Print(“hello”, “there”) => hello there

Here’s an example of how you would write functions to produce the square of a number, and print it!

NOTE! If the end of a function body is reached without executing a return statement, that function call produces value “None”.

Additional Notes from this Lesson:

Triple quoted strings can span several lines. Example:

Print(‘’’ How

Are

You?’’’)

In memory, this is stored as ‘How\nAre\nYou?’ (\n is the newline designation)

Character Designations!

\t is an escape sequence for tabs

\\ is to print a single backslash

\’ is for ‘ in a string

\” is for “ in a string

Lesson 4: Docstring & Function Help

Docstring is documentation for your own functions! Make sure that these are triple quoted so they are formatted correctly. Something I thought was really neat here was that the first two lines of your docstring are what show up as the hint when you begin to type the function name.

Lesson 5: Function Design Recipe

  1. Header – includes your function name & parameters
  2. Type contract – types for values of parameters & expected return type
  3. Description – C’mon kids! J
  4. Examples – Function use examples.
  5. Function Body – your code to make things happen!

Next comes the Design Recipe, which is crafted, of course, to make things easier for you to execute as a developer.

1.    Write examples
2.    Write type contract
          a.    What times for the parameters?
          b.    What type needs to be returned?
3.    Write header
          a.    Pick meaningful parameter names
4.    Write description
          a.    Mention every parameter and describe your return value
5.    Write body!

Lesson 6: Function Reuse

Once defined, you can use your functions over and over again! You can even pass your function calls as arguments. Get. On. It.

Lesson 7: Visualizing Function Calls

Formatting note: All code belonging to a function should be indented 4 spaces.

Stack Frame: a region of computer memory for keeping track of information about a function being executed

Locak Variable: variable created inside a function body that can only be accessed within that function.

Week 2 Summary:

This week was awesome because it took concepts that I’ve worked with before and brought them into the Python context. I’m excited to see what’s on tap for next week, especially since this course is also incorporating a Design Recipe, similar to Systematic Programming.

Questions/Comments?

Feel free to comment here on my blog, or find me on Twitter @DokiDara.

By Dara Monasch


Comments  (37 )

D-Coding
on Thu, Sep 26 2013 4:14 PM

This week’s worth of lessons is super intuitive and really sets the tone for the rest of the class

D-Coding
on Wed, Oct 2 2013 12:24 PM

This week is pretty strongly centered around working with Strings, whether it be using operators, indexing

mayur shah
on Sat, Mar 19 2016 7:53 AM

good Another Snapchat upgrade has added new attributes here 's the best way to utilize the http://snapchattrophiess.com new features including slo-mo and rewind filters. nice.

William Gomez
on Thu, May 26 2016 3:18 AM

Thanks a lot for sharing such great information with us.

https://snap-tube.com

Mary Prior
on Fri, Jun 10 2016 6:19 AM

application software for android, iOS and windows

http://playboxhdapk.com/

Mary Prior
on Fri, Jun 10 2016 6:20 AM

application software for android, iOS and windows

http://playboxhdapk.com/

Becki Muller
on Tue, Jun 21 2016 7:53 AM

its really great application man, checkout for cool movie streaming http://www.showboxappz.com/

albert steyn
on Wed, Sep 7 2016 8:02 AM

now you can visiti this url https://showbox-download.com/ for more info

Robby Asian
on Thu, Sep 15 2016 3:16 AM

The showbox killer app

find more at here

http://terrariumtv.org

Robby Asian
on Thu, Sep 15 2016 3:17 AM

http://terrariumtv.org what is the problem with this

abishek setty
on Tue, Oct 4 2016 8:06 AM

Features of Kingroot app checkout here

<a href="kingrootapkdownload.net/">kingroot apk download</a>

Ankila Bhardwaj
on Mon, Oct 10 2016 6:56 AM
matt bourne
on Wed, Oct 19 2016 2:36 AM

download the showbox newer version for pc and as well as the iphoone ...

www.appforpcshub.com/showbox-for-pc

matt bourne
on Wed, Oct 19 2016 2:38 AM

download the showbox newer version for pc and as well as the iphoone ...

www.appforpcshub.com/showbox-for-pc

john atkins
on Sat, Oct 22 2016 3:10 AM

thanks for all the information you have given here ..!!

thabks for sharing such informative article !

http://www.megaboxhdapk.org/

reni syafitri
on Wed, Oct 26 2016 4:54 AM

Bissmillah, Allohumma Yassir Walaa Tu'assir :) Thanks for the information, Very useful

www.obatherbalterlaris.com/.../merk-suplemen-detox-terbaik

james polc
on Sat, Nov 19 2016 7:16 AM

Best showbox alternative to watch movies.

terrariumtvdownloadapp.com

james polc
on Sat, Nov 19 2016 7:19 AM

Visit this site <a href="terrariumtvdownloadapp.com/.../a>

na zumi
on Thu, Dec 15 2016 4:29 AM

I really wanted to send a small word to say thanks to you for the fantastic points you are writing on this site.

http://flipdiving.online

na zumi
on Thu, Dec 15 2016 4:31 AM

- I really wanted to send a small word to say thanks to you for the fantastic points you are writing on this site.

http://flipdiving.online

aily cyrus
on Wed, Jan 4 2017 2:13 AM

THANX FOR SHARING THIS ARTICLE CONTAINING LOADS OF MEANINGFUL DATA!!!

mike jenniva
on Sat, Jan 7 2017 3:38 AM

Pythin is very essential for many programming languages. Python is also used on <a href="tcsultimatixwebmail.com/">TCS Web mail zimbra</a>.

juhu buhu
on Mon, Jan 9 2017 9:58 AM

photo or even video to group of friends in just a single click. In short this app makes the experience of texting a lot better for sure. That’s why it’s essential to download Apple iMessage for Windows on your system to experience the exciting features of this amazing app developed by Apple Inc. on Windows PC :-  devsgeek.us/imessage-on-pc

steve cook
on Thu, Jan 19 2017 4:27 AM

thanks for sharing this good article http://lucky-patcher.co/

jenny cyrus
on Sun, Feb 19 2017 4:58 AM
Jessica Seibold
on Tue, Feb 28 2017 12:33 PM

www.doraemonepisodes.xyz hey pls visit here

kevin nguyen
on Tue, Mar 7 2017 11:30 AM

Wonderful and useful piece of information. Thanks http://www.kizi2.com

iroot
on Mon, Mar 13 2017 1:17 AM

i must say you have some awesome writing skills in you you can also check this blog for rooting information https://www.irootapk.net/

iroot
on Mon, Mar 13 2017 1:19 AM

YOU ARE THE BEST BRO KEEP IT UP https://www.irootapk.net/

Mike
on Tue, Mar 21 2017 9:16 AM

THANX FOR SHARING THIS ARTICLE CONTAINING LOADS OF MEANINGFUL DATA!!!!!!!

you are the bestttest bro. thank you http://www.playredeemcard.com/ www.googleplayredeemcode.com googleplayredeemcodesfree.tumblr.com

Mike
on Tue, Mar 21 2017 9:17 AM

i must say you have some awesome writing skills in you you can also check this blog for good information! http://www.playredeemcard.com/

USPS
on Tue, Apr 4 2017 7:10 AM

It’s really a nice and useful piece of info. I’m glad that you just shared this helpful information with us. Please stay us up to date like this. Thank you for sharing.

uspstrackingnumbers.com

john
on Fri, Apr 7 2017 11:02 AM

A wonderful and useful piece of information. Thanks runapkgames.com/movietube-apk-download-movie-tube

Chelpus
on Mon, Apr 10 2017 5:02 PM

It's really nice to download lucky patcher. download from official website - http://www.luckypatcherapk.me

HD Movies App
on Tue, Apr 18 2017 4:05 AM

It sounds like you are gathering lots of different ideas in your blog.  Good work. Instead of thinking about what you haven’t written  I really appreciate the effort in publishing this article http://hdmovieapp.com/ Thanks dear

HD Movies App
on Tue, Apr 18 2017 4:06 AM

It sounds like you are gathering lots of different ideas in your blog.  Good work. Instead of thinking about what you haven’t written  I really appreciate the effort in publishing this article http://hdmovieapp.com/ Thanks dear

Jonathan
on Wed, Apr 19 2017 4:20 AM

Showbox is one of the best apps among all the others which provide streaming of movies and tv shows.

The best part is, it is absolutely free for everyone and it also provides multiple resolutions of the videos.

You can also watch the videos even when you are offline showboxforpcc.com/showbox-for-ios