From Botdom Wiki
Jump to navigation Jump to search
Paradigm Multiple: object-oriented, imperative, functional
Appeared in 1991
Designed by Guido van Rossum
Developer Python Software Foundation
Latest release 2.5.2
Influenced by ABC, ALGOL 68, C, Haskell, Icon, Lisp, Modula-3, Perl, Java


A new version of Python has come out, Version 3.1.2. In version 3.1.2, the syntax is different from 2.5.2. So perhaps a new page or section should be created with the new syntax and information.

Python is a very high-level dynamic object-oriented programming language that can be used for many kinds of software development. It has been used to creating a few bot systems on dAmn.

Basic syntax


<python>string = "This is a string in Python!"</python>

Different types of quote marks work with Python:

<python># This will work. string = "Python string's rock!"

  1. This will too.

string = 'Python strings rock!'

  1. Escaping quote marks normally

string = 'Python string\'s rock!'</python>

To print a string, issue the <python-inline>print</python-inline> statement: <python>print "Hello, world!"</python>

You can also simply save it in variables and then handle variables like in most other languages. <python>string = "This is a Python string!" print string</python>

Writing multi-line strings in Python is done using triple quotes: <python-inline>"""</python-inline> or <python-inline></python-inline>, like so: <python>print """ This is an example of a multi-line string in python. """</python>

Strings can also be concatenated, and the easiest method of achieving this is using the <python-inline>+</python-inline> operator: <python>string = 'this is' + ' ' + 'a string'</python>

Strings can also be repeated with the <python-inline>*</python-inline> operator: <python>print "test" * 5

  1. outputs: testtesttesttesttest


Strings also support indexes: <python>string = 'test0' print string[4]

  1. outputs: t</python>

We printed the 4th indexed character in the string, which is "t" in this case.


Lists (known as non-associative arrays in other languages) are fairly easy, below is a simple example of how to use them:

<python>l = ['bot', 'dom'] print l

  1. outputs: ['bot', 'dom']

print l[0]

  1. outputs: bot

print l[1]

  1. outputs: dom


You can also merge several lists using the <python-inline>+</python-inline> operator <python> print ['bot','dom'] + ['foo','bar']

  1. outputs: ['bot','dom','foo','bar']</python>

For more information, there is a great guide on Python programming over at Wikibooks.

Blazer has written a small tutorial on the basics of programming in Pythong 3.1 here!

Bots created using Python