• Complain

Thurlow - Python

Here you can read online Thurlow - Python full text of the book (entire story) in english for free. Download pdf and epub, get meaning, cover and reviews about this ebook. genre: Computer. Description of the work, (preface) as well as reviews are available. Best literature library LitArk.com created for fans of good reading and offers a wide selection of genres:

Romance novel Science fiction Adventure Detective Science History Home and family Prose Art Politics Computer Non-fiction Religion Business Children Humor

Choose a favorite category and find really read worthwhile books. Enjoy immersion in the world of imagination, feel the emotions of the characters or learn something new for yourself, make an fascinating discovery.

No cover

Python: summary, description and annotation

We offer to read an annotation, description, summary or preface (depends on what the author of the book "Python" wrote himself). If you haven't found the necessary information about the book — write in the comments, we will try to find it.

A Python and XML tutorial aimed at Civilization IV modding

Thurlow: author's other books


Who wrote Python? Find out the surname, the name of the author of the book and a list of all author's works by series.

Python — read online for free the complete book (whole text) full work

Below is the text of the book, divided by pages. System saving the place of the last page read, allows you to conveniently read the book "Python" online for free, without having to search again every time where you left off. Put a bookmark, and you can go to the page where you finished reading at any time.

Light

Font size:

Reset

Interval:

Bookmark:

Make
Installing Python
What is python?

If you don't understand this, don't worry. Just skip it and move on.

Python is an interpretedprogramming language. For those who don't know, a programming language is what you write down to tell a computer what to do. However, the computer doesn't read the language directly - there are hundreds of programming languages, and it couldn't understand them all. So, when someone writes a program, they will write it in their language of choice, and then compile it - that is, turn it in to lots of 0s and 1s, that the computer can easily and quickly understand. A windows program that you buy is already compiled for windows - if you opened the program file up, you'd just get a mass of weird characters and rectangles. Give it a go - find a small windows program, and open it up in notepad or wordpad. See what garbled mess you get.

But that windows program is compiled for windows - no other machine can run that program, unless it has windows. What Python is, is a language which is never actually compiled in full - instead, an interpreter turns each line of code into 0s and 1s that your computer can understand this. And it is done on the fly - it compiles the bits of the program you are using as you are using them. If you were to quit the program and come back another day, it would compile the bits you are using, as you are using them, again. Seems a waste of time? Maybe, but the fact is that when you come back another day, you might be using a Windows instead of a Mac. You might send the program to a friend, who uses another type of computer. Or you might post your program on the internet, where everyone using all different types of systems might download it. That is the wonder of an interpreted programming language - it is like a language that EVERYONE can understand.

So why will civIV use Python?
Image 1 - The garbled mess of a compiled program

Remember that garbled mess that you got when opening a program in notepad? Not much use to anyone, apart from the computer. And there is no reliable (or legal) way of turning that program back in to a programming language that you or I could understand.

The same is with Civ3 AI - it is compiled into a garbled mess. Nobody can understand it, and most of all, nobody can change it. Only Firaxis can change the AI, and they can't share the logic behind it with anyone.

With cIV, they decided to change that - they would leave the AI uncompiled in the language of Python, and have it compiled on-the-fly by an interpreter. This is so that Joe modder can look at the AI and change it, yet when it is neede to be used, the python interpreter turns it into 0s and 1s for your computer to understand. And it isn't permanently compiled into a garbled mess - you are still left with python code, that you can read, understand, and MODIFY!!!!!

How to install python
  1. First download Python-2.4.1.exe by following this link. If you are a dialup user, keep in mind that the file is around 10MB
  2. Run the file you just downloaded, and follow the prompts.

OK! Hopefully now everything is good! Now, to test if that just worked, type this in your DOS window:

Code Example 1 - Testing the installation
python -V

If you forgot a CAPITAL V, you will accidently load python in verbose mode. Give it a go, see what happens. Just press CTRL-D to quit, or type 'quit' for quit instructions.

conclusion

Good work! Lesson 1 over! Next lesson, we learn our way around Python Interactive Mode, and write simple one-line pieces of code. I'll also have a lesson plan drawn up by then, so you can see where you are going. If any of our more experienced members have suggestions for the lesson plan, tell me!

Thanks to all,

sthurlow.com


Very simple 'programs'
Introduction

OK! We have python installed, now what? Well, we program!

And it is that simple (at least for now). Python makes it easy to run single lines of code - one-liner programs. Lets give it a go.

Opening IDLE

Go to the start menu, find Python, and run the program labelled 'IDLE' (Stands for Integrated Development Environment.

Now you are in the IDLE environment. This is the place you will be spending most time in. Here you can open a new window to write a program, or you can simply mess around with single lines of code, which is what we are going to do. Type the following and press enter: (don't type >>> as it should already be there)

Code Example 1 - Hello, World!
>>> print "Hello, World!"

What happened? You just created a program, that prints the words 'Hello, World'. The IDLE environment that you are in immediately compiles whatever you have typed in. This is useful for testing things, e.g. define a few variables, and then test to see if a certain line will work. That will come in a later lesson, though.

Math in Python

Now try typing the stuff in bold. You should get the output shown in blue. I've given explainations in brackets.

Code Example 2 - Maths
>>> 1 + 12>>> 20+80100>>> 18294+449566467860(These are additions)>>> 6-51(Subtraction)>>> 2*510(Multiply, rabbits!)>>> 5**225(Exponentials e.g. this one is 5 squared)>>> print "1 + 2 is an addition"1 + 2 is an addition(the print statement, which writes something onscreen)>>> print "one kilobyte is 2^10 bytes, or", 2**10, "bytes"one kilobyte is 2^10 bytes, or 1024 bytes(you can print sums and variables in a sentence.The commas seperating each section are a way ofseperating clearly different things that you are printing)>>> 21/37>>> 23/37>>> 23.0/3.07.6666...(division, 2nd time ignoring remainder/decimals,3rd time including decimals)>>> 23%32>>> 49%109(the remainder from a division)

As you see, there is the code, then the result of that code. I then explain them in brackets. These are the basic commands of python, and what they do. Here is a table to clarify them (because tables look cool, and make you feel smarter ;) ):

Table 1 - Python operators
commandnameexampleoutput
+Addition4+59
-Subtraction8-53
*Multiplication4*520
/Division19/36
%Remainder19%35
**Exponent2**416

Remember that thing called order of operation that they taught in maths? Well, it applies in python, too. Here it is, if you need reminding:

  1. parentheses ()
  2. exponents **
  3. multiplication *, division \, and remainder %
  4. addition + and subtraction -
Order of Operations

Here are some examples that you might want to try, if you're rusty on this:

Code Example 3 - Order of Operations
>>> 1 + 2 * 37>>> (1 + 2) * 39

In the first example, the computer calculates 2 * 3 first, then adds 1 to it. This is because multiplication has the higher priority (at 3) and addition is below that (at lowly 4).

In the second example, the computer calculates 1 + 2 first, then multiplies it by 3. This is because parentheses (brackets, like the ones that are surrounding this interluding text ;) ) have the higher priority (at 1) and addition comes in later than that.

Also remember that the math is calculated from left to right, UNLESS you put in parentheses. The innermost parentheses are calculated first. Watch these examples:

Next page
Light

Font size:

Reset

Interval:

Bookmark:

Make

Similar books «Python»

Look at similar books to Python. We have selected literature similar in name and meaning in the hope of providing readers with more options to find new, interesting, not yet read works.


Reviews about «Python»

Discussion, reviews of the book Python and just readers' own opinions. Leave your comments, write what you think about the work, its meaning or the main characters. Specify what exactly you liked and what you didn't like, and why you think so.