QP School

Full Version: Everything you need to know about Python 3
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Python 3 is the latest major version of the Python programming language. It was released on December 3, 2008, and it is the successor to Python 2. Python 3 introduced several improvements, new features, and syntax changes over Python 2. Here's everything you need to know about Python 3:

Print Statement: In Python 3, the print statement was replaced by the print function. Now, you need to use parentheses when printing, like print("Hello, World!").

Unicode Support: Python 3 fully embraces Unicode, making it the default string type. Strings are now Unicode by default, and you can directly use special characters from various languages.

Integer Division: In Python 3, the division of two integers results in a float if the division is not evenly divisible. To perform integer division, you need to use the // operator.

range() Function: The range() function in Python 3 behaves like Python 2's xrange() function, producing an iterator instead of a list. To get a list, you can use list(range()).

input() Function: The input() function in Python 3 reads input as a string. In Python 2, it was equivalent to Python 3's raw_input().

Syntax Changes: Python 3 introduced various syntax changes, such as using as for the with statement, using raise Exception from cause for exception chaining, and more.

Print Formatting: Python 3 introduced new-style string formatting using curly braces {} and the format() method instead of the % operator.

Dictionary Views: Python 3 introduced dictionary views, which provide dynamic views of the dictionary's keys, values, and items. This allows efficient iteration and changes to the original dictionary.

Type Annotations: Python 3 introduced support for type annotations, allowing you to add hints about the types of variables and function return values. This enhances code readability and can be used by static type checkers like mypy.

Keyword-Only Arguments: Python 3 allows defining functions with keyword-only arguments, which ensures that certain arguments can only be passed using keyword syntax.

Async/Await: Python 3 introduced native support for asynchronous programming with the async and await keywords, making it easier to write asynchronous code using coroutines.

Backward Incompatibility: Python 3 is not fully backward compatible with Python 2. Some Python 2 code might need modifications to run on Python 3.

Python 3 is the recommended version for all new Python projects, as Python 2 reached its end-of-life on January 1, 2020. Python 3 offers improved performance, enhanced features, and a more future-proof language foundation. The Python community actively maintains and develops Python 3, and many third-party libraries and frameworks have transitioned to support Python 3 exclusively.