This preview has intentionally blurred parts. Sign up to view the full document

View Full Document

Unformatted Document Excerpt

CS313E: Elements of Software Design Basic Python Dr. Bill Young Department of Computer Sciences University of Texas at Austin Last updated: October 9, 2012 at 13:10 CS313E Slideset 2: 1 Basic Java Acknowledgement Much of the material in this introductory slideset is from Dr. Shyamal Mitra, and used with his blessing. CS313E Slideset 2: 2 Basic Java Introduction to Python Python is a simple but powerful scripting language. It was developed by Guido van Rossum in the Netherlands in the late 1980s. The language takes its name from the British comedy series Monty Pythons Flying Circus . Python is an interpreted language unlike C or Fortran that are compiled languages. Clean syntax that is concise. You can say a lot more with fewer words. Design is compact. You can carry all the language constructs in your head. There is a very powerful library of useful functions available. This means that you can be productive quite easily and fast. You will be spending more time solving problems and writing code than grappling with the idiosyncrasies of the language. CS313E Slideset 2: 3 Basic Java Running Python: Interactively There are several ways to run Python. One is to start Python and run programs in the interactive loop . > python3 >>> print ("Hello World!") Hello World! This uses the read-execute-print loop. 1 Read in a legal Python form. 2 Execute the form. 3 Print the result to standard output. 4 Go to step 1. CS313E Slideset 2: 4 Basic Java Running Python: From File For longer programs you can store your program in a file that ends with a .py extension. Example: saved in a file called Hello.py is the single statement: print ("Hello World!") To run your program, type at the command line > python Hello.py You can also create a stand alone script. On a Unix / Linux machine you can create a script called Hello.py containing the following lines (assuming thats where your Python implementation lives): #!/lusr/bin/python print ("Hello World!") CS313E Slideset 2: 5 Basic Java Running Python: From File Lets try running this: > Hello.py Hello.py: Permission denied. What went wrong? Before you run it, you must tell Linux that its an executable file: > chmod +x Hello.py Then run it: > Hello.py Hello World! CS313E Slideset 2: 6 Basic Java Structure of a Computer Language Character set Variables Types Operators Assignments Conditionals Loops Functions Arrays Input / Output CS313E Slideset 2: 7 Basic Java Basic Syntax: Character Set Python uses the traditional ASCII character set. Recent versions also recognize the Unicode character set. The ASCII character set is a subset of the Unicode character set. Python does not have a separate character type. A character is represented as a string containing one item (e.g., "a" ).... View Full Document

End of Preview

Sign up now to access the rest of the document