1 / 16

Python

Python. Programming Languages. Computers cannot understand English. Human languages are too expressive – there are too many ways to say something. At least for giving complex sequences of instructions (programs). . Programming Languages.

skule
Download Presentation

Python

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Python

  2. Programming Languages • Computers cannot understand English. • Human languages are too expressive – there are too many ways to say something. • At least for giving complex sequences of instructions (programs).

  3. Programming Languages • The set of instructions that the computer can understand is very small. • On most modern processors about 100. • The types of instructions are very simple: • Move a number from one place to another • Perform arithmetic on some numbers • Test to see whether a value is equal to some other value • Humans can program at this level, but don’t like to.

  4. Programming Languages • Programming languages provide a bridge between human languages and what the computer can understand. • Programming languages are less expressive than human languages, so the computer can translate to it’s own language. • We have to do some translation ourselves, from human language to the programming language.

  5. Interpretation vs. Compilation • This translation from a programming language to machine language can happen in a couple of different ways.

  6. Compilation • One way to do this translation is by compilation. • A program, called a compiler, translates the whole program to machine language and saves the translated version. • When we run the program, we’re running the saved machine language version. • Think of translating a book to another language.

  7. Interpretation • Another way to do this is by interpretation. • A program, called an interpreter, translates one command to machine language and the computer does it. • Then the interpreter does it again with the next command, and so on. • No translated copy is produced. • Think of simultaneous translation (like at the U.N.)

  8. Interpretation vs. Compilation • Interpreted programs are slower. • Although compilation takes a while, it doesn’t happen every time you want to run your program.

  9. Compiling http://xkcd.com/303/

  10. Interpretation vs. Compilation • Interpretation is more flexible – you can experiment more easily. • Interpretation allows for interactive programming – typing one command at a time and seeing the result.

  11. IDLE Environment • IDLE is an interactive development environment for the Python interpreter. • Lets you try out individual commands. • Also lets you write full programs.

  12. Interaction in the Interpreter • Whenever you type something at the prompt, you get back a response: >>> 5 5 • What you got back was the value of what you typed. • The interpreter evaluated what you typed.

  13. Evaluation • Numbers have pretty obvious value. • Expressions have a pretty obvious value as well. >>> 5+2 7

  14. Strings • Sometimes we want to work with text. • Strings are used to specify text. >>> ‘Hello’ ‘Hello’ • A string has a value too.

  15. String Delimiters • We need to tell the interpreter where strings begin and end. • Otherwise it can tell the difference between text and commands. • And variables – we’ll get to those later. • Strings can be delimited with either single or double quotes. • ‘Hello’ • “Hello”

  16. String Delimiters • You can use single and double quotes together because sometimes we want to put quotes inside a string. • ‘He said “Hello” to her’ • Just be sure you match your quotes or you will get errors.

More Related