Be insensitive, and keep a lifelong growth mindset.

0%

Learn Python Basics Learning Notes I

I. Python for Beginners

Introduction

Python is a language with widespread adoption and lots of uses.

Python Variable

Example:

1
name = "Danny"

Fuctions and Objects

Example:

1
2
def my_function_name():
print("this is the function body")

Syntax and Style

Every programming language has specific words and rules for using them which we call syntax. Some languages also have rules about how the code should look. Python has both of these!
Blocks are indented one extra step.Each indentation step should be four spaces (just hit tab)

1
2
3
def answer_the_phone():
greeting = "Hi, this is Kenneth. Who is this?"
print(greeting)

The Python Shell

In Mac, just type “python” in terminal to enter python shell, and type “exit()” to quit.

Running Python Scripts

Example to run a python script in python shell:
treehouse:~/workspace$ python hello_world.py

Errors:

*NameError: *
Example: 5 + x
Got the error because the x is not defined.

TypeError: 5 + ‘a’
Got the error because 5 and ‘a’ are different types, and can not be added.

SyntaxError:
Example: print(“Hello)
Got the error because of missing the syntax “

II. Python Data Types

TBD

III. Logic in Python

TBD