
# 'Invisible' control characters and escape sequences

# Control characters modify the flow of characters on the screen
# or in a text file.
# They do not appear visually as some kind of symbols.


'''
 An escape sequence is a sequence of characters
that does not represent itself
when used inside a character or string literal.
It is translated into another character
or a sequence of characters that may be difficult
or impossible to represent directly.

In C [and in Python too], all escape sequences consist
of two or more characters, the first of which
is the backslash, \ (called the "Escape character");
the remaining characters determine the interpretation
of the escape sequence.

[https://en.wikipedia.org/wiki/Escape_sequences_in_C]
'''


# ..............................................................
# NEW LINE CONTROL CHARACTER \n
# ..............................................................

# Most common control character is 'new line' denoted as \n.

print( "Explore:" , "\n\n" + "the new line \\n character" )
print()
print( "a \n b \n c \n\n d.\n ------------"  )


# Note 1
# Repated \n character ( "\n\n" ) causes repeated effect.
# the text skips to new line *twice* after printing "Explore".
# This also produces one empty line.
# Triple \n character ( "\n\n\n" ) would produce two empty lines.
# Try it.

# Note 2
# The control character is written as two (or more) symbols:
# backslash and n:  '\n'
# Backslash is the leading symbol for all control characters.
# So the symbol \ no longer represents the backslash itself.
# To print the backslash, it must be doubled:

print("Three backslashes: ", "\\\\\\")
print("Three separate backslashes: ", "\\, \\, \\.")
print()

# Note 3
# Each print() command in Python appends by default
# one \n character to the output it produces.
# This default can be overridden by specifying
# another (or none) character to be appended:

print( "No line end after this sentence.", end = "" )
print( " This output continues on the same line." )
print()
for i in range(3):
    print(" [end = \"--\"] ", end = "--" )
print()
print()

# Note 4
# To put quotes symbol into the string literal
# precede it by backslash: \". See also the code above.

print( "a \"string\" is a string" )
print("Quotation mark: \"")
print("Two quotation marks: \"\"")
print("Two single quotation marks: ''")
print('Two single quotation marks: \'\'')


# ..............................................................
# TABULATOR CONTROL CHARACTER \t
# ..............................................................

# Tabulator \t character is much less ubiquitous than \n.
# It just inserts a tabulator (= few spaces) into the text.
# It moves the text to the next so-called tab stop
# which is usually a horizontal position divisible by 8.
# The result typically contains horizontal blanks
# of different lengths.

print( "Hottest bathtubs attract fittest artists." );
print( "Ho\t\tes\t ba\th\tubs a\t\tract fi\t\tes\t ar\tis\ts." )

# Remaining less frequent escape sequences: see
# https://www.python-ds.com/python-3-escape-sequences

