Python Foundation Documentation

website·Indexed 29 days ago

https://prepverse.github.io/docs

Foundational guides for Python programming, covering getting started, finding an interpreter, using the print() function, and creating comments for maintainable code.

Tokens
914
Snippets
7
Records
8
Agent score
75%

What's inside Python Foundation

  1. Overview of Python language features

    Python is a high-level, general-purpose language with the following characteristics:

    • Interpreted: Source code is converted to bytecode and then machine language; no separate compilation step is required.
    • Platform Independent: Runs on Windows, Linux, macOS, and Solaris.
    • High-Level: Abstracts low-level memory management.
    • Embeddable: Can be integrated into C/C++ programs for scripting.
    • Standard Library: Follows a "batteries included" philosophy, providing built-in modules for regex, unit testing, threading, databases, and more.
    • Open Source: Free to use and distribute.
  2. Install or find a Python interpreter

    To run Python programs, you need an interpreter. Depending on your environment, use the following methods:

    • Online: Use web-based interpreters to run code without local installation.
    • Windows: Download and install Python from python.org. This includes IDLE (Integrated Development and Learning Environment).
    • Linux: Most distributions (e.g., Ubuntu, Fedora) come with Python preinstalled. Verify the installation by running python in the terminal.
    • macOS: Python 2.7 is often preinstalled. For Python 3, download and install it from python.org.
    # Check Python version on Linux/macOS
    python --version
  3. Create single-line comments in Python

    In Python, comments start with the # symbol. The Python interpreter ignores everything following the # on that same line. Comments are used to explain code functionality, improve readability, and temporarily disable specific lines of code for debugging.
    # This is a comment in Python.
    print("Hello, World!")
  4. Create multi-line comments in Python

    Python does not have a dedicated built-in syntax for multi-line comments, but there are two common ways to achieve this:

    1. Prefix every line with the # symbol.
    2. Use triple quotes (""" or ''') to create a multiline string. Since Python ignores string literals that are not assigned to a variable, they effectively act as comments.
    # Method 1: Using # for each line
    # This way we can
    # Write comments in 
    # Multiple lines. 
    print("Hello, World!")
    
    # Method 2: Using triple quotes
    """
    Another way to write
    comments in more than one
    Line.
    """
    print("Hello, World!")
  5. Control separators and line endings in print()

    Use the sep parameter to change the character used between multiple arguments and the end parameter to change what is printed at the end of the line (instead of the default newline).
    # Using sep to change the separator from space to hyphen
    print("Python", "is", "fun", sep="-")
    # Output: Python-is-fun
    
    # Using end to prevent a newline and add a custom string
    print("Welcome to PrepVerse", end=" ** ")
    print("Learn Python")
    # Output: Welcome to PrepVerse ** Learn Python
  6. Use the print() function to output text in Python

    The print() function outputs messages to the screen or any other standard output device. It converts all provided values to strings before printing. The function does not return a value.
    print("Welcome to PrepVerse")
  7. Configure print() parameters for output formatting

    The print() function accepts several optional parameters to control how output is displayed:

    • value(s): The object(s) to be printed.
    • sep: Specifies the separator between multiple values. Defaults to a space ' '.
    • end: Specifies the character printed at the end of the call. Defaults to a newline '\n'.
    • file: An object with a write method (defaults to sys.stdout).
    • flush: A boolean determining if the output is flushed immediately (True) or buffered (False). Defaults to False.
    print(value(s), sep=' ', end='\n', file=file, flush=flush)