
# A string is a sequence of characters.
# String manipulation is closely related to human text reading and writing.

# When defining a string (so called string literal)
# enclose it in double or single quotation marks.
# Double quotation marks are better visually.

stringInfo1 = "Strings lesson is in progress."
stringInfo2 = 'Single quotation marks are also allowed.'

print( stringInfo1, stringInfo2 )
print()

# -------------------------------------------------------------
# empty string

# note there is nothing between the quotation marks
empty = ""

print("Here comes an empty string:", empty, "is it visible? ")
print()

# -------------------------------------------------------------
# Accessing parts of string

# Access schemes are analogous to lists,
# square brackets and slicing is used.

stringInfo = "Strings lesson is in progress."
print( stringInfo[0], stringInfo[1], stringInfo[2], stringInfo[3], "..." )
print()

# Length function len()
# Print the string character by character ( utterly artificial method ).
for i in range( 0, len(stringInfo) ):
    print( stringInfo[i], end = "" )
print()

print()

# Negative indices are analogous to lists.
for i in range( 1, len(stringInfo)+1 ):
    print( stringInfo[-i], end = "" )
print()
print()


# -------------------------------------------------------------
# Creating strings from other strings

# String consisting of concatenation of other strings
op = " times "
eq = " equals "
n1 = "13"
n2 = "10"
example = n1 + op + n2 + eq + str( int(n1) * int(n2) )
print (example)
print()



# -------------------------------------------------------------
# A small digression

# Interestingly, just simple addition, when repeated,
# produces very quickly a very long string
s = "A short string. "
for i in range( 7 ):
    s = s + s
# Inspect the result:
print( "result length is", len(s) )
if len(s) < 10000:
    print( s )
print()
# setting range to more than 26 (or so) crashes the program
# (MemoryError)

# the same scheme holds for number too, of course:
x = 1
for i in range(100):
    x = x + x
    print( x )
print(x)
print()

# -------------------------------------------------------------
# String consisting of multiple copies of the same string
s = "Hi! "
s5 =  s * 4
print( s5 )







