I started yesterday with Python, as it is my first (programming) language it seemed to be a logical choice after doing some research. Nonetheless i started with a book called "Python Programming for the Absolute Beginner", and its all going great, atleast in my opinion. But, (a minor but) i do seem to struggle (obviously) by associating the functions of the programming i'm learning on to implementing it.
PS: It could be because my mind is clogged with all this new information
Anyway, this was the script/program that just didn't make sense to me allthough i understand its function.
# Pizza Slicer
# Demonstrates string slicing
# Xxxxx Xxxxxxxx - 19/10/10
word = "pizza"
print \
"""
Slicing 'Cheat Sheet'
0 1 2 3 4 5
+-----+-----+-----+-----+-----+
| P | I | Z | Z | A |
+-----+-----+-----+-----+-----+
-5 -4 -3 -2 -1
"""
print "Enter the beginning and ending index for your slice of 'pizza'."
print "Press the enter key at 'Begin' to exit."
begin = None
while begin != "":
begin = (raw_input("\nBegin: "))
if begin:
begin = int(begin)
end = int(raw_input("End: "))
print "word[", begin, ":", end, "]\t\t",
print word[begin:end]
raw_input("\n\nPress the enter key to exit.")
Do i want to slice because strings are immutable? and therefore slicing is one of the alternatives?
Also, could i be explained when and why i want to slice. Or is this simply a matter of time before i'd understand when and why?
:confused:


Sign In
Create Account


Back to top









