Sunday, May 29, 2011

Python exercise: convert Strings

exercise:
print("Python exercise: String")

HelloString = "hEllO PYTHON!"
print(HelloString)

print ("capitalize(): " + HelloString.capitalize())
print ("title(): " + HelloString.title())
print ("upper():" + HelloString.upper())
print ("lower()" + HelloString.lower())


output:
Python exercise: convert Strings

Python exercise: Slicing Strings

exercise:
HelloString = "Hello Python!"
print(HelloString)

print("Python exercise: Slicing Strings")
print (HelloString[2:10]) #from index 2 to 10-1
print (HelloString[2:]) #from index 2 to end
print (HelloString[:10]) #from begin to 10-1
print (HelloString[::3]) #every 3 characters
print (HelloString[::-1]) #every characters in reverse order


output:
Python exercise: Slicing Strings

Python exercise: get character in string using negative indexing

exercise:
HelloString = "Python!"
print(HelloString)

StringLen = len(HelloString)
print("String Length: " + str(StringLen))

print("Print in normal order")
for i in range(0, StringLen):
print(HelloString[i])

print("Print in reverse order, negative indexing")
for i in range(1, StringLen+1):
print(HelloString[-i])



output:
Python exercise: get character in string using negative indexing

Saturday, May 21, 2011

Download Python 2.5.4 for Windows

If you want to develop Python with PyGame on Windows, may be you prefer to download Python 2.5.4 rather than the current 2.7.1 or 3.2.

According to Pygame download page: python2.5.4 is the best python on windows at the moment.

Python 2.5.4 can be downloaded here.

Other old release are listed here.

Download Python for Windows


Python is available to download in http://www.python.org/download/.

The current production versions are Python 2.7.1 and Python 3.2.

If you don't know which version to use, start with Python 2.7; more existing third party software is compatible with Python 2 than Python 3 right now.