This repository contains small Python projects and guides for beginners.
There are three markdown files that will lead you through a series of steps to learn some beginner Python programming.
You will use the Python interpreter to learn about variables, functions, and classes.
Make sure you TYPE the snippets from the markdown files into the Python interpreter.
Not typing, doing copy/paste, will not help you learn (and is cheating at this point of the course)
Make sure you have Python installed on your system:
python3 --versionIf you don't have Python installed:
- macOS: Install via Homebrew:
brew install python3
Unlike Java which requires jshell for interactive programming, Python is interpreted by default.
To start the Python interpreter:
python3You should see the Python prompt:
Python 3.x.x (default, ...)
[GCC ...] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
To exit the Python interpreter:
- Type
exit()and press Enter - Or press
Ctrl+D(Linux/macOS) orCtrl+Zthen Enter (Windows)
| Feature | Java | Python |
|---|---|---|
| Interactive Shell | jshell |
Built-in interpreter |
| Variable Declaration | int x = 5; |
x = 5 |
| String Concatenation | "Hello " + name |
f"Hello {name}" |
| Method Definition | public void method() {} |
def method(): |
| Class Constructor | ClassName(params) {} |
def __init__(self, params): |
| Boolean Values | true, false |
True, False |
| Code Blocks | { } |
Indentation |
Use a browser to be able to see the markdown files.
Start with PythonSmall.md and follow the links to the other guides:
- PythonSmall.md - Learn Python basics with the interpreter
- VARS.md - Understanding Python variables and types
- ClassPerson.md - Creating and using Python classes
- Type, don't copy-paste - Build muscle memory
- Experiment freely - Python interpreter is forgiving
- Use meaningful variable names - Python encourages readability
- Pay attention to indentation - Python uses whitespace for structure
- Read error messages - Python error messages are helpful
- Variable names: Use
snake_case(notcamelCase) - Function names: Use
snake_case - Class names: Use
PascalCase - Constants: Use
UPPER_CASE - Indentation: Use 4 spaces (not tabs)
- Python files:
.py - Python interactive files: Can be saved as
.pyfiles
Once you create a Python file (like hello.py), run it with:
python3 hello.py- Python official documentation: https://docs.python.org/3/
- Python tutorial: https://docs.python.org/3/tutorial/
- Learn Python the Hard Way: https://learnpythonthehardway.org/
In the Python interpreter:
help()- Interactive helpdir(object)- Show object attributestype(variable)- Show variable typehelp(function)- Help for specific function
Start your Python journey with PythonSmall.md!