Difference between revisions of "Python1"

From SourceWiki
Jump to navigation Jump to search
Line 36: Line 36:
 
you'll get:
 
you'll get:
  
<pre>
+
<source lang="python">
 
Hello!
 
Hello!
</pre>
+
</source>
  
 
If you try:
 
If you try:
Line 48: Line 48:
 
you'll get:
 
you'll get:
  
<pre>
+
<source lang="python">
 
14
 
14
</pre>
+
</source>
 +
 
 +
And here is a copy of a session containing a few more commands:
 +
 
 +
<source lang="python">
 +
>>> five = 5
 +
>>> neuf = 9
 +
>>> print five + neuf
 +
14
 +
>>> def say_hello():
 +
...    print "Hello, world!"
 +
... # hit return here
 +
>>> say_hello()
 +
Hello, world!
 +
</source>
  
 
=Getting Help=
 
=Getting Help=
  
 
Python has lots of useful documentation.  For example, take a look at: http://docs.python.org/.
 
Python has lots of useful documentation.  For example, take a look at: http://docs.python.org/.

Revision as of 14:39, 2 October 2012

Python for Scientists

Introduction

http://xkcd.com/353/

Getting Started on BlueCrystal Phase-2

After you have logged in, type the following at the command line:

module add languages/python-2.7.2.0
python

This should start up an interactive python session:

Python 2.7.2 (default, Aug 25 2011, 10:51:03) 
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>

where we can type commands at the >>> prompt.

Python as a Calculator

Let's try a few commands out. If you type:

>>> print "Hello!"

you'll get:

Hello!

If you try:

>>> print 5 + 9

you'll get:

14

And here is a copy of a session containing a few more commands:

>>> five = 5
>>> neuf = 9
>>> print five + neuf
14
>>> def say_hello():
...     print "Hello, world!"
... # hit return here 
>>> say_hello()
Hello, world!

Getting Help

Python has lots of useful documentation. For example, take a look at: http://docs.python.org/.