CS61A(1): Computer Science

This is the lecture note of CS61A - Lecture 1.

What is Computer Science?

Computer Science has many subfields, and each subfield has its own sub-subfield.

What is this course about?

  • A course about managing complexity, thus you should:
    • master abstraction
      • procedural abstractions
      • data abstractions
    • master programming paradigms
  • An introduction to programming:
    • full understanding of Python fundamentals
    • combine multiple ideas in large projects
    • learn how computer interpret programming languages
  • Different types of languages:
    • Python
    • Scheme
    • SQL

Demo

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# Numeric expressions
2020
2000 + 20
-1 + 2 + 3 + 4 * ((5 // 6) + 7 * 8 * 9)

# Functions
abs(-2)
abs(2301 - 4321)

# Values
"Go Bears"
"Gob" + "ears"

# Objects
from urllib.request import urlopen

shakes = urlopen('http://composingprograms.com/shakespeare.txt')
text = shakes.read().decode().split()
len(text)
text[:25]
text.count('the')
text.count('thou')
text.count('you')
text.count('forsooth')
text.count(',')

# Sets
words = set(text)
len(words)

# Combinations
'draw'
'draw'[0] # 'd'
{w[0] for w in words}

# Data
'draw'[::-1] # 'ward'
{w for w in words if w == w[::-1] and len(w)>4}
{w for w in words if w[::-1] in words and len(w) == 4}
{w for w in words if w[::-1] in words and len(w) > 6}