background preloader

Python

Facebook Twitter

Www.greenteapress.com/thinkpython/thinkpython.pdf. Introduction to Electrical Engineering and Computer Science I | Electrical Engineering and Computer Science. Think Python. 2. Using the Python Interpreter — Python v3.3.2 documentation. 2.1. Invoking the Interpreter The Python interpreter is usually installed as /usr/local/bin/python3.3 on those machines where it is available; putting /usr/local/bin in your Unix shell’s search path makes it possible to start it by typing the command: to the shell.

Since the choice of the directory where the interpreter lives is an installation option, other places are possible; check with your local Python guru or system administrator. (E.g., /usr/local/python is a popular alternative location.) On Windows machines, the Python installation is usually placed in C:\Python33 , though you can change this when you’re running the installer. Set path =% path % ; C : \ python33 Typing an end-of-file character ( Control-D on Unix, Control-Z on Windows) at the primary prompt causes the interpreter to exit with a zero exit status.

The interpreter’s line-editing features usually aren’t very sophisticated. Some Python modules are also useful as scripts. 2.1.1. 2.1.2. 2.2. 2.2.1. 2.2.2. . #! 2.2.3. Lesson 3 - Programs in a file, and variables. Introduction Well, we can make one-liner programs. So What? You want to send programs to other people, so that they can use them, without knowing how to write them. Editing in Notepad Writing programs in python to a file is VERY easy. Code Example 1 - mary.py #A simple program. print "Mary had a little lamb," print "it's fleece was white as snow;" print "and everywhere that Mary went", print "her lamb was sure to go. " Keep this exactly the same, down to where the commas are placed. Using the IDLE Environment Now, open up the Python IDLE program (should be in your start menu). Code Example 2 - mary.py output Mary had a little lamb, it's fleece was white as snow; and everywhere that Mary went her lamb was sure to go.

You can also use IDLE to create Python programs, like what you did in notepad. There are a couple of things to notice here: First of all, the comment wasn't shown. Variables Now lets start introducing variables. Code Example 3 - Variables Strings Code Example 4 - Strings Conclusion. Learn Python - Free Interactive Python Tutorial. Our Mission. Ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-01sc-introduction-to-electrical-engineering-and-computer-science-i-spring-2011/python-tutorial/part-i/MIT6_01SCS11_python01.pdf.