Its design philosophy emphasizes code readability, and its syntax allows programmers to express concepts in fewer lines of code than would be possible in languages such as C. The language provides constructs intended to enable clear programs on both a small and large scale.[20]
Python supports multiple programming paradigms, including object-oriented, imperative and functional programming or procedural styles. It features a dynamic type system and automatic memory management and has a large and comprehensive standard library.
Scripting language created by Guido van Rossum
Published in 1991 (23 years ago)
Most places these days we know about use it for web programming.
Python is great at getting an application created quickly and cleanly
http://www.reddit.com/r/Python/comments/1dsv7m/what_is_python_not_a_good_language_for/
Everyone needs to go to http://python.org/download
python -V
in the terminalbrew install python
In [1]:
print "hello world"
In [2]:
1+1
Out[2]:
In [3]:
1/2
Out[3]:
Notice for later: Not true division
In [4]:
1//2
Out[4]:
In [5]:
print "hello " * 4
In [6]:
item = [1,2,3,4,5,6]
print item
print type(item)
In [7]:
print item[3:4]
print item[:4]
print item[3:]
In [8]:
myDict = {"key":"value", "name":"chris"}
In [9]:
print myDict
In [10]:
print "My name is %s" % myDict['name']
In [11]:
item = "5"
if item == 5:
print "It's 5"
elif item == "5":
print "It's %s" % item
else:
print "I don't know what it is."
In [12]:
item = "5"
if item is not None:
print "item isn't None"
else:
print "item is None"
print "---\nSetting item to None\n---"
item = None
if item is None:
print "item is None"
In [13]:
my_list = [1, 2, 3]
my_strings = ["things", "stuff", "abc"]
In [14]:
for item in my_list:
print "Item %d" % item
In [15]:
for (index, string) in enumerate(my_strings):
print "Index of %d and value of %s" % (index, string)
In [16]:
print "Type of my_list is %s and the first element is %s" % (type(my_list), type(my_list[0]))
In [17]:
print dir(my_list)
In [18]:
class A_old():
pass
class A_new(object):
pass
print "Old type %s and New type %s" % (type(A_old), type(A_new))
In [19]:
my_old_a = A_old()
my_new_a = A_new()
print "Old object %s and New object %s" % (type(my_old_a), type(my_new_a))
In Python variables are more like "tags" than "boxes"
Normal ![](http://python.net/~goodger/projects/pycon/2007/idiomatic/a2box.png) ![](http://python.net/~goodger/projects/pycon/2007/idiomatic/b2box.png) | Python ![](http://python.net/~goodger/projects/pycon/2007/idiomatic/a2tag.png) ![](http://python.net/~goodger/projects/pycon/2007/idiomatic/ab2tag.png) |
In [20]:
item = [1, 2, 3]
In [21]:
item is item
Out[21]:
In [22]:
item is item[:]
Out[22]:
In [23]:
item == item[:]
Out[23]:
Question and answer
In [6]:
import re
user = {}
user['name'] = raw_input("What is your name? ")
user['quest'] = raw_input("What is your quest? ")
user['will-get-shrubbery'] = raw_input("We want.... ONE SHRUBBERY. ")
user['favorite-color'] = raw_input('What is your favorite colour? ')
print '-'*60
accepted = re.compile(r"^((sure|SURE)|(y|Y).*)")
accepted_status = "will acquire"
if accepted.search(user['will-get-shrubbery']) is None:
accepted_status = "will not aquire"
print "%s is on a quest %s and %s a shrubbery. His favorite color is %s" % (user['name'].title(),
user['quest'].lower(), accepted_status , user['favorite-color'].upper())
In [ ]: