CS61A 01. Functions

welcome

two insructors:
John DeNero [email protected]
Paul Hilfinger [email protected]

parts of the lecture

Lecture: Videos posted to cs61a.org before each live lecture
Lab section: The most important part of this course (next week)
Discussion section: The most important part of this course (this week)
Staff office hours: The most important part of this course (next week)
Online textbook: http://composingprograms.com

Weekly homework assignments, three exams, & four programming projects
Lots of optional special events to help you complete all this work

What is Computer Science?

CS61A 01. Functions_第1张图片
What is Computer Science

What is this course about?

A course about managing complexity

  • Mastering abstraction
  • Programming paradigms

An introduction to programming

  • Full understanding of Python fundamentals
  • Combining multiple ideas in large projects
  • How computers interpret programming languages

Different types of languages: Scheme & SQL

A challenging course that will demand a lot of you

Collaboration

Asking questions is highly encouraged

  • Discuss everything with each other; learn from your fellow students!
  • Projects 3 & 4 can be completed with a partner
  • Choose a partner from your discussion section

The limits of collaboration

  • One simple rule: Don’t share your code, except with your project partner
  • Copying project solutions causes people to fail the course
  • We really do catch people who violate the rules

Build good habits now

Types of expressions

An expression describes a computation and evaluates to a value


CS61A 01. Functions_第2张图片
different types of expressions

All expressions can use function call notation

Anatomy of a Call Expression

CS61A 01. Functions_第3张图片
call expression

Evaluating Nested Expressions

CS61A 01. Functions_第4张图片
nested expression

Functions, Values, Objects, Interpreters, and Data

在第一节课的最后,John用了一个有趣的检索莎士比亚的例子来说明Python的两大组成部分。
其中open(), count()属于函数 functions,
set(text)属于对象 objects,
函数和对象间的组织方式和电脑回复是编程语言本身,
目前为止所有键盘输入的内容都叫做 Expressions,

control + L 清屏


CS61A 01. Functions_第5张图片
Screen Shot 2018-01-25 at 20.54.24.png

Lab00

Summary

Here is a summary of the commands we just went over for your reference:

  • ls: lists all files in the current directory
  • cd : change into the specified directory
  • mkdir : make a new directory with the given name
  • mv : move the file at the given source to the given destination

Finally, you're ready to start editing the lab files! Don't worry if this seems complicated -- it will get much easier over time. Just keep practicing! You can also take a look at our UNIX tutorial for a more detailed explanation of terminal commands.

OK

To test a specific question, use the -q option with the name of the question:

python3 ok -q 

Test all questions

python3 ok

Submit assignment
When you are ready to submit, run ok with the --submit option:

python3 ok --submit

Appendix: Useful Python command line options

When running a Python file, you can use options on the command line to inspect your code further. Here are a few that will come in handy. If you want to learn more about other Python command-line options, take a look at the documentation.

  • Using no command-line options will run the code in the file you provide and return you to the command line.

    python3 lab00.py
    
  • -i: The -i option runs your Python script, then opens an interactive session. In an interactive session, you run Python code line by line and get immediate feedback instead of running an entire file all at once. To exit, type exit() into the interpreter prompt. You can also use the keyboard shortcut Ctrl-D on Linux/Mac machines or Ctrl-Z Enter on Windows.

    If you edit the Python file while running it interactively, you will need to exit and restart the interpreter in order for those changes to take effect.

    python3 -i lab00.py
    
  • -m doctest: Runs doctests in a particular file. Doctests are surrounded by triple quotes (""") within functions. Each test consists of >>> followed by some Python code and the expected output.

     python3 -m doctest lab00.py
    

你可能感兴趣的:(CS61A 01. Functions)