Introduction: Python Programming - Slices

Short Python program that demonstrates how to use slices (segments) of a string.
Below and attached.
========================================

print ("This program will print slices (segments) of strings.")

StringEntered = input("Enter a word or phrase: ")
StringLength = len(StringEntered)
print ("The length of the string is: ", StringLength)

# Calculate half the length of the string and round it off
HalfLengthOfString=StringLength/2
RoundedNumber = round(HalfLengthOfString)
print ("Half the length of the string (rounded) is approximately: ", RoundedNumber)

# Break out the first portion
print ("The first portion of the string is: ")
print (StringEntered[0:RoundedNumber])

# Break out the second portion
print ("The second portion of the string is: ")
print (StringEntered[RoundedNumber:])

Comments

About This Instructable

287views

7favorites

License:

More by matt392:Multi-Bit Screwdriver From Pine 1x2Hand Drill From Husky Ratcheting Screwdriver​Small House/Creche Made of Wood Shims
Add instructable to: