<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="http://wiki.darenet.org/skins/common/feed.css?12"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
	<channel>
		<title>Python en:First Steps - Revision history</title>
		<link>http://wiki.darenet.org/index.php?title=Python_en:First_Steps&amp;action=history</link>
		<description>Revision history for this page on the wiki</description>
		<language>en</language>
		<generator>MediaWiki 1.15.1</generator>
		<lastBuildDate>Thu, 21 May 2026 05:47:33 GMT</lastBuildDate>
		<item>
			<title>Admin:&amp;#32;1 revision</title>
			<link>http://wiki.darenet.org/index.php?title=Python_en:First_Steps&amp;diff=5532&amp;oldid=prev</link>
			<description>&lt;p&gt;1 revision&lt;/p&gt;

		&lt;table style=&quot;background-color: white; color:black;&quot;&gt;
		&lt;col class='diff-marker' /&gt;
		&lt;col class='diff-content' /&gt;
		&lt;col class='diff-marker' /&gt;
		&lt;col class='diff-content' /&gt;
		&lt;tr valign='top'&gt;
		&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;← Older revision&lt;/td&gt;
		&lt;td colspan='2' style=&quot;background-color: white; color:black;&quot;&gt;Revision as of 02:52, 3 April 2010&lt;/td&gt;
		&lt;/tr&gt;
		&lt;!-- diff generator: internal 2026-05-21 04:58:14 --&gt;

&lt;!-- diff cache key wiki:diff:version:1.11a:oldid:5531:newid:5532 --&gt;
&lt;/table&gt;</description>
			<pubDate>Sat, 03 Apr 2010 02:52:48 GMT</pubDate>			<dc:creator>Admin</dc:creator>			<comments>http://wiki.darenet.org/Talk:Python_en:First_Steps</comments>		</item>
		<item>
			<title>70.44.102.3:&amp;#32;/* Introduction */</title>
			<link>http://wiki.darenet.org/index.php?title=Python_en:First_Steps&amp;diff=5531&amp;oldid=prev</link>
			<description>&lt;p&gt;&lt;span class=&quot;autocomment&quot;&gt;Introduction&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;lt;div class=&amp;quot;python book&amp;quot;&amp;gt;&lt;br /&gt;
== Introduction  ==&lt;br /&gt;
&lt;br /&gt;
We will now see how to run a traditional 'Hello World' program in Python. This will teach you how to write, save and run Python programs. &lt;br /&gt;
&lt;br /&gt;
There are two ways of using Python to run your program - using the interactive interpreter prompt or using a source file. We will now see how to use both of these methods&lt;br /&gt;
&lt;br /&gt;
== Using The Interpreter Prompt  ==&lt;br /&gt;
&lt;br /&gt;
Start the interpreter on the command line by entering &amp;lt;tt&amp;gt;python&amp;lt;/tt&amp;gt; at the shell prompt. &lt;br /&gt;
&lt;br /&gt;
For Windows users, you can run the interpreter in the command line if you have set the &amp;lt;tt&amp;gt;PATH&amp;lt;/tt&amp;gt; variable appropriately.&lt;br /&gt;
&lt;br /&gt;
If you are using IDLE, click on &amp;lt;tt&amp;gt;Start&amp;lt;/tt&amp;gt; &amp;amp;rarr; &amp;lt;tt&amp;gt;Programs&amp;lt;/tt&amp;gt; &amp;amp;rarr; &amp;lt;tt&amp;gt;Python 3.0&amp;lt;/tt&amp;gt; &amp;amp;rarr; &amp;lt;tt&amp;gt;IDLE (Python GUI)&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Now enter &amp;lt;tt&amp;gt;print('Hello World')&amp;lt;/tt&amp;gt; followed by the &amp;lt;tt&amp;gt;Enter&amp;lt;/tt&amp;gt; key. You should see the words &amp;lt;tt&amp;gt;Hello World&amp;lt;/tt&amp;gt; as output. &lt;br /&gt;
&lt;br /&gt;
    $ python&lt;br /&gt;
    Python 3.0b2 (r30b2:65106, Jul 18 2008, 18:44:17) [MSC v.1500 32 bit (Intel)] on win32&lt;br /&gt;
    Type &amp;quot;help&amp;quot;, &amp;quot;copyright&amp;quot;, &amp;quot;credits&amp;quot; or &amp;quot;license&amp;quot; for more information.&lt;br /&gt;
    &amp;amp;gt;&amp;amp;gt;&amp;amp;gt; print('Hello World')&lt;br /&gt;
    Hello World&lt;br /&gt;
    &amp;amp;gt;&amp;amp;gt;&amp;amp;gt;&lt;br /&gt;
&lt;br /&gt;
Notice that Python gives you the output of the line immediately! What you just entered is a single Python ''statement''. We use &amp;lt;tt&amp;gt;print&amp;lt;/tt&amp;gt; to (unsurprisingly) print any value that you supply to it. Here, we are supplying the text &amp;lt;tt&amp;gt;Hello World&amp;lt;/tt&amp;gt; and this is promptly printed to the screen. &lt;br /&gt;
&lt;br /&gt;
;How to Quit the Interpreter Prompt &lt;br /&gt;
:To exit the prompt, press &amp;lt;tt&amp;gt;ctrl-d&amp;lt;/tt&amp;gt; if you are using IDLE or are using a Linux/BSD shell. In case of the Windows command prompt, press &amp;lt;tt&amp;gt;ctrl-z&amp;lt;/tt&amp;gt; followed by &amp;lt;tt&amp;gt;enter&amp;lt;/tt&amp;gt; key.&lt;br /&gt;
&lt;br /&gt;
== Choosing An Editor  ==&lt;br /&gt;
&lt;br /&gt;
Before we move on to writing Python programs in source files, we need an editor to write the source files. The choice of an editor is crucial indeed. You have to choose an editor as you would choose a car you would buy. A good editor will help you write Python programs easily, making your journey more comfortable and helps you reach your destination (achieve your goal) in a much faster and safer way. &lt;br /&gt;
&lt;br /&gt;
One of the very basic requirements is '''syntax highlighting''' where all the different parts of your Python program are colorized so that you can ''see'' your program and visualize its running. &lt;br /&gt;
&lt;br /&gt;
If you are using Windows, then I suggest that you use IDLE. IDLE does syntax highlighting and a lot more such as allowing you to run your programs within IDLE among other things. A special note: '''Do not use Notepad''' - it is a bad choice because it does not do syntax highlighting and also importantly it does not support indentation of the text which is very important in our case as we will see later. Good editors such as IDLE (and also VIM) will automatically help you do this. &lt;br /&gt;
&lt;br /&gt;
If you are using Linux/FreeBSD, then you have a lot of choices for an editor. If you are just beginning to program, you might want to use geany. It has a graphical user interface and has buttons to compile and run your python program without a fuss.&lt;br /&gt;
&lt;br /&gt;
If you are an experienced programmer, then you must be already using &amp;lt;tt&amp;gt;Vim&amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt;Emacs&amp;lt;/tt&amp;gt;. Needless to say, these are two of the most powerful editors and you will be benefitted by using them to write your Python programs. I personally use &amp;lt;tt&amp;gt;Vim&amp;lt;/tt&amp;gt; for most of my programs. If you are a beginner programmer, then you can use &amp;lt;tt&amp;gt;Kate&amp;lt;/tt&amp;gt; which is one of my favorites. In case you are willing to take the time to learn Vim or Emacs, then I highly recommend that you do learn to use either of them as it will be very useful for you in the long run. &lt;br /&gt;
&lt;br /&gt;
In this book, we will use '''IDLE''', our IDE and editor of choice. IDLE is installed by default with the Windows and Mac OS X Python installers. It is also available for installation for [http://love-python.blogspot.com/2008/03/install-idle-in-linux.html Linux] and BSDs in their respective repositories. &lt;br /&gt;
&lt;br /&gt;
We will explore how to use IDLE in the next section. For further details, please refer the [http://www.python.org/idle/doc/idlemain.html IDLE documentation]. &lt;br /&gt;
&lt;br /&gt;
If you still want to explore other choices of an editor, see the comprehensive [http://www.python.org/cgi-bin/moinmoin/PythonEditors list of Python editors] and make your choice. You can also choose an IDE (Integrated Development Environment) for Python. See the comprehensive [http://www.python.org/cgi-bin/moinmoin/IntegratedDevelopmentEnvironments list of IDEs that support Python] for more details. Once you start writing large Python programs, IDEs can be very useful indeed. &lt;br /&gt;
&lt;br /&gt;
I repeat once again, please choose a proper editor - it can make writing Python programs more fun and easy. &lt;br /&gt;
&lt;br /&gt;
;For Vim users &lt;br /&gt;
:There is a good introduction on how to [http://blog.sontek.net/2008/05/11/python-with-a-modular-ide-vim/ make Vim a powerful Python IDE by John M Anderson]. &lt;br /&gt;
;For Emacs users &lt;br /&gt;
:There is a good introduction on how to [http://www.enigmacurry.com/2008/05/09/emacs-as-a-powerful-python-ide/ make Emacs a powerful Python IDE by Ryan McGuire].&lt;br /&gt;
&lt;br /&gt;
== Using A Source File  ==&lt;br /&gt;
&lt;br /&gt;
Now let's get back to programming. There is a tradition that whenever you learn a new programming language, the first program that you write and run is the 'Hello World' program - all it does is just say 'Hello World' when you run it. As Simon Cozens &amp;lt;ref&amp;gt;The author of the amazing 'Beginning Perl' book&amp;lt;/ref&amp;gt; puts it, it is the 'traditional incantation to the programming gods to help you learn the language better' :) . &lt;br /&gt;
&lt;br /&gt;
Start your choice of editor, enter the following program and save it as &amp;lt;tt&amp;gt;helloworld.py&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If you are using IDLE, click on &amp;lt;tt&amp;gt;File&amp;lt;/tt&amp;gt; &amp;amp;rarr; &amp;lt;tt&amp;gt;New Window&amp;lt;/tt&amp;gt; and enter the following program. Then click on &amp;lt;tt&amp;gt;File&amp;lt;/tt&amp;gt; &amp;amp;rarr; &amp;lt;tt&amp;gt;Save&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#!/usr/bin/python &lt;br /&gt;
#Filename: helloworld.py&lt;br /&gt;
&lt;br /&gt;
print('Hello World') &lt;br /&gt;
&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Run this program by opening a shell (Linux terminal or DOS prompt) and entering the command &amp;lt;tt&amp;gt;python helloworld.py&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
If you are using IDLE, use the menu &amp;lt;tt&amp;gt;Run&amp;lt;/tt&amp;gt; &amp;amp;rarr; &amp;lt;tt&amp;gt;Run Module&amp;lt;/tt&amp;gt; or the keyboard shortcut &amp;lt;tt&amp;gt;F5&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
The output is as shown below. &lt;br /&gt;
&lt;br /&gt;
    $ python helloworld.py&lt;br /&gt;
    Hello World&lt;br /&gt;
&lt;br /&gt;
If you got the output as shown above, congratulations! - you have successfully run your first Python program. &lt;br /&gt;
&lt;br /&gt;
In case you got an error, please type the above program ''exactly'' as shown and above and run the program again. Note that Python is case-sensitive i.e. &amp;lt;tt&amp;gt;print&amp;lt;/tt&amp;gt; is not the same as &amp;lt;tt&amp;gt;Print&amp;lt;/tt&amp;gt; - note the lowercase &amp;lt;tt&amp;gt;p&amp;lt;/tt&amp;gt; in the former and the uppercase &amp;lt;tt&amp;gt;P&amp;lt;/tt&amp;gt; in the latter. Also, ensure there are no spaces or tabs before the first character in each line - we will see why this is important later. &lt;br /&gt;
&lt;br /&gt;
=== How It Works  ===&lt;br /&gt;
&lt;br /&gt;
Let us consider the first two lines of the program. These are called ''comments'' - anything to the right of the &amp;lt;tt&amp;gt;#&amp;lt;/tt&amp;gt; symbol is a comment and is mainly useful as notes for the reader of the program. &lt;br /&gt;
&lt;br /&gt;
Python does not use comments except for the special case of the first line here. It is called the ''shebang line'' - whenever the first two characters of the source file are &amp;lt;tt&amp;gt;#!&amp;lt;/tt&amp;gt; followed by the location of a program, this tells your Linux/Unix system that this program should be run with this interpreter when you ''execute'' the program. This is explained in detail in the next section. Note that you can always run the program on any platform by specifying the interpreter directly on the command line such as the command &amp;lt;tt&amp;gt;python helloworld.py&amp;lt;/tt&amp;gt; . &lt;br /&gt;
&lt;br /&gt;
;Important &lt;br /&gt;
:Use comments sensibly in your program to explain some important details of your program - this is useful for readers of your program so that they can easily understand what the program is doing. Remember, that person can be yourself after six months!&lt;br /&gt;
&lt;br /&gt;
The comments are followed by a Python ''statement''. Here we call the &amp;lt;tt&amp;gt;print&amp;lt;/tt&amp;gt; ''function'' this just prints the text &amp;lt;tt&amp;gt;'Hello World'&amp;lt;/tt&amp;gt;. We will learn about functions in a [[Python en:Functions|later chapter]], what you should understand now is that whatever you supply in the parentheses will be printed back to the screen. In this case, we supply &amp;lt;tt&amp;gt;'Hello World'&amp;lt;/tt&amp;gt; which is referred to as a string - don't worry, we will explore these terminologies in detail later. &lt;br /&gt;
&lt;br /&gt;
=== Executable Python Programs  ===&lt;br /&gt;
&lt;br /&gt;
This applies only to Linux/Unix users but Windows users might be curious as well about the first line of the program. First, we have to give the program executable permission using the &amp;lt;tt&amp;gt;chmod&amp;lt;/tt&amp;gt; command then ''run'' the source program. &lt;br /&gt;
&lt;br /&gt;
    $ chmod a+x helloworld.py&lt;br /&gt;
    $ ./helloworld.py&lt;br /&gt;
    Hello World&lt;br /&gt;
&lt;br /&gt;
The chmod command is used here to ''ch''ange the ''mod''e of the file by giving e''x''ecute permission to ''a''ll users of the system. Then, we execute the program directly by specifying the location of the source file. We use the &amp;lt;tt&amp;gt;./&amp;lt;/tt&amp;gt; to indicate that the program is located in the current directory. &lt;br /&gt;
&lt;br /&gt;
To make things more fun, you can rename the file to just &amp;lt;tt&amp;gt;helloworld&amp;lt;/tt&amp;gt; and run it as &amp;lt;tt&amp;gt;./helloworld&amp;lt;/tt&amp;gt; and it will still work since the system knows that it has to run the program using the interpreter whose location is specified in the first line in the source file. &lt;br /&gt;
&lt;br /&gt;
What if you don't know where Python is located? Then, you can use the special &amp;lt;tt&amp;gt;env&amp;lt;/tt&amp;gt; program on Linux/Unix systems. Just change the first line of the program to the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;env&amp;lt;/tt&amp;gt; program will in turn look for the Python interpreter which will run the program.&lt;br /&gt;
&lt;br /&gt;
So far, we have been able to run our program as long as we know the exact path. What if we wanted to be able to run the program from anywhere? You can do this by storing the program in one of the directories listed in the &amp;lt;tt&amp;gt;PATH&amp;lt;/tt&amp;gt; environment variable. Whenever you run any program, the system looks for that program in each of the directories listed in the &amp;lt;tt&amp;gt;PATH&amp;lt;/tt&amp;gt; environment variable and then runs that program. We can make this program available everywhere by simply copying this source file to one of the directories listed in &amp;lt;tt&amp;gt;PATH&amp;lt;/tt&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
    $ echo $PATH&lt;br /&gt;
    /usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:/home/swaroop/bin&lt;br /&gt;
    $ cp helloworld.py /home/swaroop/bin/helloworld&lt;br /&gt;
    $ helloworld&lt;br /&gt;
    Hello World&lt;br /&gt;
&lt;br /&gt;
We can display the &amp;lt;tt&amp;gt;PATH&amp;lt;/tt&amp;gt; variable using the &amp;lt;tt&amp;gt;echo&amp;lt;/tt&amp;gt; command and prefixing the variable name by &amp;lt;tt&amp;gt;$&amp;lt;/tt&amp;gt; to indicate to the shell that we need the value of this variable. We see that &amp;lt;tt&amp;gt;/home/swaroop/bin&amp;lt;/tt&amp;gt; is one of the directories in the PATH variable where ''swaroop'' is the username I am using in my system. There will usually be a similar directory for your username on your system. Alternatively, you can add a directory of your choice to the &amp;lt;tt&amp;gt;PATH&amp;lt;/tt&amp;gt; variable - this can be done by running &amp;lt;tt&amp;gt;PATH=$PATH:/home/swaroop/mydir&amp;lt;/tt&amp;gt; where &amp;lt;tt&amp;gt;'/home/swaroop/mydir'&amp;lt;/tt&amp;gt; is the directory I want to add to the &amp;lt;tt&amp;gt;PATH&amp;lt;/tt&amp;gt; variable. &lt;br /&gt;
&lt;br /&gt;
This method is very useful if you want to write useful scripts that you want to run the program anytime, anywhere. It is like creating your own commands just like &amp;lt;tt&amp;gt;cd&amp;lt;/tt&amp;gt; or any other commands that you use in the Linux terminal or DOS prompt. &lt;br /&gt;
&lt;br /&gt;
;Caution &lt;br /&gt;
:W.r.t. Python, a program or a script or software all mean the same thing.&lt;br /&gt;
&lt;br /&gt;
== Getting Help  ==&lt;br /&gt;
&lt;br /&gt;
If you need quick information about any function or statement in Python, then you can use the built-in &amp;lt;tt&amp;gt;help&amp;lt;/tt&amp;gt; functionality. This is very useful especially when using the interpreter prompt. For example, run &amp;lt;tt&amp;gt;help(print)&amp;lt;/tt&amp;gt; - this displays the help for the print function which is used to print things to the screen. &lt;br /&gt;
&lt;br /&gt;
;Note &lt;br /&gt;
:Press &amp;lt;tt&amp;gt;q&amp;lt;/tt&amp;gt; to exit the help.&lt;br /&gt;
&lt;br /&gt;
Similarly, you can obtain information about almost anything in Python. Use &amp;lt;tt&amp;gt;help()&amp;lt;/tt&amp;gt; to learn more about using &amp;lt;tt&amp;gt;help&amp;lt;/tt&amp;gt; itself! &lt;br /&gt;
&lt;br /&gt;
In case you need to get help for operators like &amp;lt;tt&amp;gt;return&amp;lt;/tt&amp;gt;, then you need to put those inside quotes such as &amp;lt;tt&amp;gt;help('return')&amp;lt;/tt&amp;gt; so that Python doesn't get confused on what we're trying to do. &lt;br /&gt;
&lt;br /&gt;
== Summary  ==&lt;br /&gt;
&lt;br /&gt;
You should now be able to write, save and run Python programs at ease. Now that you are a Python user, let's learn some more Python concepts. &lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br /&amp;gt;&lt;br /&gt;
References: &amp;lt;br /&amp;gt;&lt;br /&gt;
&amp;lt;references/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
----&lt;br /&gt;
&amp;lt;div class=&amp;quot;paging&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;span class=&amp;quot;prev&amp;quot;&amp;gt;[[Python en:Installation|Previous]]&amp;lt;/span&amp;gt; &amp;lt;span class=&amp;quot;next&amp;quot;&amp;gt;[[Python en:Basics|Next]]&amp;lt;/span&amp;gt; &lt;br /&gt;
&amp;lt;/div&amp;gt; &amp;lt;/div&amp;gt; &lt;br /&gt;
[[Category:A_Byte_of_Python|First Steps]]&lt;/div&gt;</description>
			<pubDate>Wed, 18 Mar 2009 19:10:28 GMT</pubDate>			<dc:creator>70.44.102.3</dc:creator>			<comments>http://wiki.darenet.org/Talk:Python_en:First_Steps</comments>		</item>
	</channel>
</rss>