Introduction to Python - 🐧#

In this section, I wanted to introduce a few basic concepts and give an outline of this section.

Comments in Python#

In Python, we can create comments in the code itself. Considering we can use markdown language (as you see here 😁), we won’t use this too much in this notebook. Though, here is an example.

Basically, you use the… umm… hashtag? Number sign? Pound sign?

This thing -> #

# I am a comment in Python
# Here is 2 + 2
2 + 2
# As you can see, these are not "computed" using Python. 
# We are just comments for the person looking at this.
# Or... you!
4

Help Function#

The…

help()

… function is exactly what it is. It is a function to 🌟 help 🌟 you understand the basic usage of another function.

help(print)
Help on built-in function print in module builtins:

print(...)
    print(value, ..., sep=' ', end='\n', file=sys.stdout, flush=False)
    
    Prints the values to a stream, or to sys.stdout by default.
    Optional keyword arguments:
    file:  a file-like object (stream); defaults to the current sys.stdout.
    sep:   string inserted between values, default a space.
    end:   string appended after the last value, default a newline.
    flush: whether to forcibly flush the stream.

Resources#

Highly suggest looking for answers using StackOverflow

Common Errors#

One of the most common errors in Python is the dreaded

2 + 2
 3 + 3

  File "<ipython-input-1-0dcc020fd5cb>", line 2
    3 + 3
    ^
IndentationError: unexpected indent

Why does this occur? Well, because Python uses spacing or tabs to distinguish where things like loops, functions, and if/else statements start and end. So, if you add an extra space or tab at the beginning of the statement, you will see this message. If you do, check your spacing.

Note

Python can get weird with this issue. As you can, technically, start code wherever as long as you are consistent. The next cell shows an example of this… oddity.

                2+2
                3+3
6

still works!

Your turn!#

Print out the help information for a function called type().

# Add a comment here 

# Remove this and print the help for type()