Python

From Botdom Wiki

Jump to: navigation, search
Python
Python
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

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.

Contents

Basic syntax

Strings

string = "This is a string in Python!"

Different types of quote marks work with Python:

# This will work.
string = "Python string's rock!"
# This will too.
string = 'Python strings rock!'
# Escaping quote marks normally
string = 'Python string\'s rock!'

To print a string, issue the print statement:

print "Hello, world!"

You can also simply save it in variables and then handle variables like in most other languages.

string = "This is a Python string!"
print string

Writing multi-line strings in Python is done using triple quotes: """ or ''', like so:

print """
This is an example of
a multi-line string
in python.
"""

Strings can also be concatenated, and the easiest method of achieving this is using the + operator:

string = 'this is' + ' ' + 'a string'

Strings can also be repeated with the * operator:

print "test" * 5
# outputs: testtesttesttesttest

Strings also support indexes:

string = 'test0'
print string[4]
# outputs: t

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

Lists

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

l = ['bot', 'dom']
print l
# outputs: ['bot', 'dom']
 
print l[0]
# outputs: bot
 
print l[1]
# outputs: dom

You can also merge several lists using the + operator

print ['bot','dom'] + ['foo','bar']
# outputs: ['bot','dom','foo','bar']

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

Bots created using Python

Personal tools