Python, a high-level, interpreted programming language known for its simplicity and readability, has become a staple in the tech industry. Version 3, released in 2008, brought several improvements and changes, leading many to adopt it over its predecessor. If you're looking to learn or improve your Python skills, understanding keywords introduced or altered in Python 3 is a crucial step.

The transition from Python 2 to Python 3 was significant, and one of the most notable changes was the handling of print statements. In Python 2, print was a statement, while in Python 3, it's a function. This difference impacts the way you use it in your code and is one of the first keywords you'll encounter in Python 3.

Changes in print Functionality
In Python 3, print is used as a function, and you need to enclose the parameters in parentheses. This change allows for more flexibility and control over output formatting.

Here's an example of how to use the print function in Python 3: ```python print("Hello, Python 3!") ```
Keyword args and Additional Features

Python 3's print function also supports several keyword arguments, such as sep, end, and file, which can be used to customize output: ```python print("Hello", "World", sep="-", end="!", file=sys.stdout) ```
Using End and Sep for Custom Formatting
The end parameter allows you to specify what to print at the end of each output. By default, it's a newline character, but you can change it to anything you want. The sep parameter specifies how to separate multiple arguments if you're printing more than one.

The key takeaway here is that Python 3's print function offers greater control over output formatting, making it a powerful tool for creating clean, efficient code.
Introduction of 'nonlocal' Keyword
Python 3 introduced the 'nonlocal' keyword, which allows you to modify the value of a variable in an enclosing scope, even when it's present in an inner scope with the same name.

Before Python 3, you could only reference but not modify variables in enclosing scopes, which could lead to confusion and potential bugs. The 'nonlocal' keyword helps avoid these issues by explicitly defining the scope you want to modify.
Using 'nonlocal' in Nested Functions



















Consider the following example in Python 2: ```python def outer(): count = 0 def inner(): count += 1 # This will throw an UnboundLocalError print(count) inner() outer() ```
'nonlocal' in Python 3
In Python 3, you can fix this by using the 'nonlocal' keyword: ```python def outer(): count = 0 def inner(): nonlocal count count += 1 print(count) inner() outer() ```
With 'nonlocal', you can explicitly declare that you want to modify the variable in the enclosing scope, making your code more clear and predictable.
Python 3's introduction of the 'nonlocal' keyword and changes to the print function, among other updates, have significantly improved the language's functionality and adaptability. As Python continues to grow and evolve, staying up-to-date with these changes is crucial for both beginners and experienced developers. So, keep exploring, and happy coding!