edubun
English

Python

Python basics from print to small programs. Ten units take you from a one-line program to a pocket-money log, through variables, strings, numbers, lists, if, loops, functions and dictionaries. Every code sample on these pages was run in Python 3.12, and the output shown is the real output.

Progress

About this course

Python was started by Guido van Rossum, a programmer at the CWI research institute in Amsterdam. In his own short history in the official Python FAQ, he says he decided to give the idea a try during the 1989 Christmas holidays, used it in a project at work through the next year, and posted it to the USENET newsgroups in February 1991. The name has nothing to do with snakes. He was reading the scripts of the 1970s BBC comedy series Monty Python's Flying Circus and wanted a name that was short, unique and slightly mysterious.

The ten units begin with a file holding the single line print("Hello, world!"), a complete program that prints 13 characters. Values and variables come next: in algebra score = score + 5 has no solution, but in Python it is an everyday line. Strings count from 0, so "Python"[5] is n and "Python"[6] is an error. Numbers and arithmetic separate 7 / 2 = 3.5 from 7 // 2 = 3. Lists, if and elif, for and while, and functions follow, and a function that ends without return gives back None. Dictionaries bring in Seoyeon, an invented student counting twelve ballots for class representative, who finds a list awkward and wants a table that goes straight from a name to a number. The last unit reads error messages from the bottom. In 1947, engineers on the Mark II at Harvard taped a moth into their log book beside "first actual case of bug being found". The Smithsonian notes that Thomas Edison used the word bug in the 1870s, so the moth did not invent the term. Every code sample was run in Python 3.12, and the output shown is the real output.

Before you start

The first lesson starts with a single print statement, so the examples grow from a complete small program rather than a list of rules. Basic arithmetic helps when comparing division, whole-number division and remainders. Watch spaces, quotation marks and indexes closely as you read each sample beside its shown output.

When you finish

You can store values in variables, work with strings and lists, choose branches with if, and repeat actions with for and while. You can write a function that returns a value, look up dictionary entries, distinguish common indexing and key errors, and read a traceback while building the pocket-money log project.

  1. 1Running your first Python programA file that holds the single line print("Hello, world!") is a complete Python program, and running it prints 13 characters.
  2. 2Values and variablesIn algebra, score = score + 5 has no solution. In Python it is an everyday line: if score was 10, it becomes 15.
  3. 3Strings: working with textPython counts the letters of "Python" from 0, so "Python"[5] is the last letter, n, and "Python"[6] is an error.
  4. 4Numbers and arithmeticIn Python 3, 7 / 2 gives 3.5, 7 // 2 gives 3 and 7 % 2 gives the remainder 1.
  5. 5ListsA list of 5 items has indexes 0 to 4, so menu[4] is the last item and menu[5] stops the program with IndexError.
  6. 6Making decisions with ifPython checks if and each elif from the top and runs only the first branch whose condition is True; the rest are skipped.
  7. 7Repeating with for and whilerange(5) produces 0, 1, 2, 3 and 4: five numbers, and 5 is not one of them.
  8. 8Writing your own functionsA function that ends without return gives back None, which is why print(print("hi")) shows hi and then None.
  9. 9DictionariesLooking up a key that is not in a dictionary stops the program with KeyError, but d.get(key, 0) returns 0 instead.
  10. 10Reading error messages and a small projectA Python traceback is read from the bottom: the last line names the error, and the line above the code shows where it happened.
Sources for this course (6)
  • Python Software Foundation, The Python Tutorial for Python 3.12 (docs.python.org/3.12/tutorial: 2 Using the Python Interpreter, 3 An Informal Introduction to Python (numbers, text, lists), 4 More Control Flow Tools (if, for, range, break and continue, defining functions, default argument values, 4.10 coding style: 4-space indentation), 5 Data Structures (list methods, 5.5 dictionaries, insertion order), 8 Errors and Exceptions (syntax errors, exceptions, reading the traceback, handling exceptions), 15 Floating-Point Arithmetic (0.1 + 0.2))
  • Built-in Functions (docs.python.org/3.12/library/functions.html: print, input, len, int, float, str, type, round (round half to even: round(0.5) and round(-0.5) are 0, round(1.5) is 2), range, sum, min, max, sorted)
  • Built-in Types (str methods upper, lower, replace, strip; dict.get; list.append, pop, remove, sort returning None)
  • General Python FAQ (docs.python.org/3.12/faq/general.html: Guido van Rossum began Python in the 1989 Christmas holidays, posted it to USENET in February 1991, named it after Monty Python's Flying Circus)
  • Curriculum for the Korean pages: 교육부 고시 제2022-33호 [별책 10] 정보과 교육과정 (PDF read 2026-10-19: 중학교 정보 [9정03-05] 리스트 등 데이터를 순차적으로 저장하는 구조, [9정03-06] 논리 연산과 중첩 제어 구조, [9정03-07] 함수 활용과 디버거로 오류 수정, [9정03-08] 실생활 문제를 프로그래밍으로 해결, 적용 시 고려 사항 「학생의 수준을 고려하여 적합한 프로그래밍 언어를 선정」; 고등학교 정보 [12정03-04] 자료형, [12정03-05] 표준입출력, [12정03-07] 제어 구조)
  • Bug story only: Smithsonian National Museum of American History, Log Book With Computer Bug, 1947, Harvard Mark II, "first actual case of bug being found", probably not Hopper's log book (americanhistory.si.edu/collections/object/nmah_334663, read 2026-10-19)

Checked: 2026-10-19