Reserved Keywords

Python's reserved keywords and escape sequences.

Reserved Keywords

In Python, there are certain reserved keywords that have predefined meanings and cannot be used as identifiers (such as variable names or function names) in your code. Here is a list of Python reserved keywords:

  • False
  • await
  • else
  • import
  • pass
  • None
  • break
  • except
  • in
  • raise
  • True
  • class
  • finally
  • is
  • return
  • and
  • continue
  • for
  • lambda
  • try
  • as
  • def
  • from
  • nonlocal
  • while
  • assert
  • del
  • global
  • not
  • with
  • async
  • elif
  • if
  • or
  • yield
False await else import pass
None break except in raise
True class finally is return
and continue for lambda try
as def from nonlocal while
assert del global not with
async elif if or yield

These keywords are used to define the syntax and structure of the Python language and cannot be redefined or reassigned. Attempting to use any of these keywords as identifiers will result in a syntax error.

Escape Sequences

Escape sequences in Python are special characters that are used to represent non-printable characters or to produce special formatting within strings. They are represented by a backslash ('\') followed by one or more characters. Some common escape sequences in Python include:

Character Constant Meaning
\n Move to new line
\t Horizontal tab
\\ Backslash
\' Single quote
\" Double quote
\b Backspace
\r Carriage return
\f Formfeed
\nnn Octal value
\xhh Hexadecimal Representation

Demonstrating the usage:

py Copy Code
print("This is a newline.\nThis is on a new line.")
print("This is a tab.\tTabbed text here.")
print("This is a backslash: \\")
print("This is a single quote: '")
print('This is a double quote: "')
print("This is a backspace: abc\bdef")
print("This is a carriage return:\rReturn to the beginning.")
print("This is a formfeed:\fNew page.")
print("This is an octal value: \101")
print("This is a hexadecimal value: \x41")
Output:
This is a newline.    
This is on a new line.
This is a tab.  Tabbed text here.
This is a backslash: \
This is a single quote: '        
This is a double quote: "        
This is a backspace: abdef       
Return to the beginning.n:       
This is a formfeed:♀New page.    
This is an octal value: A        
This is a hexadecimal value: A

These escape sequences allow you to include special characters or control the formatting of strings within your Python code.

What's Next?

We've now entered the finance section on this platform, where you can enhance your financial literacy.