What is Python3

Brief Overview

Python 3 stands out as a top tier programming language recognized for its user nature and clear readability. It finds application across different domains spanning from web development to scientific calculations. Thanks to its syntax and comprehensible code structure Python 3 proves to be an ideal option, for both novices and seasoned developers.

Key Features

  1. Object-Oriented Programming (OOP)
    • Python 3 supports OOP, allowing developers to create reusable and modular code. Popular libraries and frameworks like Django and Flask enhance its capabilities in web development.
  2. Script Writing
    • Python 3's interpreted nature enables quick writing and running of scripts, making it efficient for tasks like automation and data processing. Libraries such as NumPy and Pandas are widely used for data analysis.
  3. Application Development
    • Python 3 is versatile, suitable for building desktop applications, command-line tools, and even mobile applications. Frameworks like PyQT and Kivy simplify the creation of graphical user interfaces (GUIs).
  4. Pre-installed in LFS
    • Python 3 is already installed in the Linux From Scratch system. Rebuilding is only necessary for including optional modules or upgrading packages.

History of Python

Guido van Rossum established Python in the 1980s as a replacement, for the ABC language. Python aims to be user friendly, readable and robust while also offering versatility. Throughout time Python has garnered popularity and has emerged as a dominant programming language utilized across different sectors.

Key Milestones

  • Python 1.0 (1994)
    • The official debut of Python as a stable and mature programming tool.
  • Python 2.0
    • Introduced features like list comprehensions.
  • Python 3.0
    • Brought significant language changes and improvements.
  • Python 3.6
    • Introduced features like preserving keyword argument order, the __init_subclass__ method, local time disambiguation, literal string formatting, and a secrets module.

Evolution from Python 2 to Python 3

Python 3 addressed limitations and inconsistencies in Python 2, making the language more efficient and user-friendly. Some major changes include:

  • Syntax Changes
    • Print became a function requiring parentheses.
  • Improved Unicode Support
    • Default string type became Unicode.
  • Internationalization and Localization
    • Easier translation of programs into different languages.

Key Features and Improvements in Python 3

  1. Simple Syntax
    • Allows developers to write clear and concise code.
  2. Extensive Libraries
    • Offers a wide range of pre-written functions and modules.
  3. Third-Party Libraries
    • Supports numerous libraries, saving development time.
  4. Multiple Programming Paradigms
    • Supports procedural, object-oriented, and functional programming.
  5. Interpreted Language
    • Quicker development cycle as it does not require compilation.
  6. Strong Support for Data Analysis and Scientific Computing
    • Libraries like NumPy, Pandas, and Matplotlib simplify data manipulation and analysis.

Getting Started with Python 3

Installing Python 3

To install Python 3:

1. Open the terminal.

2. Navigate to the desired directory using cd.

3. Download and extract the necessary files:

curl -O https://www.python.org/ftp/python/3.9.7/Python-3.9.7.tgz
tar -xf Python-3.9.7.tgz
cd Python-3.9.7

4. Configure and install Python 3:

./configure --enable-optimizations
make
sudo make install

5. Test the installation:

Setting Up a Development Environment

Consider selecting an Integrated Development Environment (IDE) such as IDE, PyCharm or Visual Studio Code. You could also explore web based IDEs, like PythonAnywhere as a choice.

Using the Command Prompt for Running Python Code

  1. Open the command prompt.
  2. Navigate to the directory containing your Python file using cd.
  3. Run the Python file:

python filename.py

Data Types and Variables in Python 3

Basic Data Types

  • Strings
    • Sequence of characters enclosed in quotes.
  • Integers
    • Whole numbers without decimal points.
  • Floats
    • Numbers with decimal points.

Lists, Tuples, and Dictionaries

  • Lists
    • Ordered and mutable collections of elements enclosed in square brackets.
  • Tuples
    • Ordered and immutable collections of elements enclosed in parentheses.
  • Dictionaries
    • Unordered collections of key-value pairs enclosed in curly braces.

Type Conversion and Type Checking

  • Type Conversion
    • Changing data type of a value using functions like int(), str(), and float().
  • Type Checking
    • Verifying a value's data type using the isinstance() function.

Control Flow in Python 3

Conditional Statements (if, elif, else)

if Statement

if condition:
    # code to be executed if condition is True


elif and else Statements

if condition1:
    # code to be executed if condition1 is True
elif condition2:
    # code to be executed if condition1 is False and condition2 is True
else:
    # code to be executed if both condition1 and condition2 are False

Create a free account to access the full topic

“It has all the necessary theory, lots of practice, and projects of different levels. I haven't skipped any of the 3000+ coding exercises.”
Andrei Maftei
Hyperskill Graduate