
# '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,
but is translated into another character
or a sequence of characters that may be difficult
or impossible to represent directly.

In C [in Python too, MB], 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\n" + "the new line \\n character" )
print()

# 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 new line end after this sentence.", end = "" )
print( " Next 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("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
# http://python-ds.com/python-3-escape-sequences

