Introduction to Computing Fundamentals and Python Environment Setup

Understanding Computers and Python

A computer is an electronic device capable of performing high-speed calculations, logical operations, and data storage. It operates based on predefined instructions and consists of two main components: hardware and software.

Hardware Architecture

Modern computers follow the Von Neumann architecture, which includes:

  • CPU (Central Processing Unit): Comprises the arithmetic logic unit (ALU) for computations and the control unit (CU) for instruction coordination. Registers within the CPU temporarily store data and instructions.
  • Memory: Includes primary memory (RAM, volatile) and secondary storage (hard drives, SSDs, etc., non-volatile).
  • I/O Devices: Input devices (keyboard, mouse) feed data into the system; output devices (monitor, printer) display or transmit results.

Software Execution Flow

  1. An application is launched by the user.
  2. The OS loads the program and its data into RAM.
  3. The CPU fetches instructions from memory, decodes them, executes operations, and repeats until completion.
  4. Final results are stored in designated memory locations.

Python Overview

Python is a high-level, interpreted programming language known for readability and versatility.

Advantages

  • Simple syntax, ideal for beginners.
  • Open-source with strong cross-platform support.
  • Rich ecosystem (libraries for web dev, data sceince, AI, etc.).
  • Supports both procedural and object-oriented paradigms.

Limitations

  • Slower execution then compiled languages like C++ due to its interpreted nature and dynamic typing.

Common Use Cases

  • Web development (Django, Flask)
  • Data enalysis and machine learning (Pandas, TensorFlow)
  • Automation scripts and system administration
  • Network tools (scanners, sniffers)
  • Desktop applications and game prototyping

Setting Up Python

Download the latest stable version (e.g., 3.9.x) from python.org. After installation, verify via terminal:

python --version

If the version appears, the interpreter is correctly installed.

Writing and Running Python Code

Python source files use the .py extension and can be edited in any text editor (e.g., Notepad++, VS Code). Example script (hello.py):

print("Hello, world!")
print("Welcome to Python.")

Run it in the terminal:

python hello.py

Common Pitfalls

  • Use English keyboard input—Chinese punctuation causes syntax errors.
  • Avoid mixing tabs and spaces for indentation.
  • Do not write multiple statements on one line unnecessarily.
  • Ensure correct file extension (.py).

Execution Modes

  • Script Mode: Save code in a .py file and execute via interpreter—used for full programs.
  • Interactive Mode: Launch python without a filename to run commands instantly—ideal for quick tests. Exit with exit() or Ctrl+D (Linux/macOS).

Using PyCharm IDE

PyCharm (from JetBrains) is a powerful IDE for Python development. Download from jetbrains.com.

Project Setup

  • Create a new project: File → New Project.
  • Project names typically use PascalCase (e.g., DataAnalyzer).
  • Python files should use lowercase letters, digits, and underscores (e.g., main_utils.py), never starting with a digit.

Interpreter Configuration

If multiple Python versions exist, specify the correct one via File → Settings → Project → Python Interpreter.

Essential PyCharm Shortcuts

Shortcut Action
Ctrl + / Toggle single-line comment
Ctrl + Shift + / Toggle block comment
Ctrl + D Duplicate current line
Ctrl + X Delete current line
Ctrl + Alt + L Reformat code
Ctrl + R Find and replace

Basic Python Syntax

Variables

Variables store data and are assigned using =:

message = "Hello, Python!"
count = 42
is_active = True

Naming Rules

  • Start with letter or underscore; no digits at start.
  • No special characters (spaces, @, $, etc.).
  • Case-sensitive (nameName).
  • Avoid Python keywords (e.g., if, for, class).

View all keywords:

import keyword
print(keyword.kwlist)

Comments

# Single-line comment

"""
Multi-line comment
Used for docstrings or explanations
"""

Code Structure

  • Line separation: Statements end with newline; semicolons are optional.
  • Indentation: Defines code blocks (e.g., in if, for, functions). Use 4 spaces per level (PEP 8 standard).

Core Data Types

Integer (int)

Represents whole numbers of arbitrary size:

x = 100
print(type(x))  # <class 'int'>

Supports binary (0b101), octal (0o12), and hexadecimal (0x1F) literals.

Floating-Point (float)

Represents real numbers:

pi = 3.14
scientific = 6.02e23  # 6.02 × 10²³

Boolean (bool)

Has two values: True and False. All data types have a "truthiness":

print(bool(0))      # False
print(bool(""))     # False
print(bool("0"))    # True
print(bool(-1))     # True

String (str)

Enclosed in single or double quotes:

s1 = 'Hello'
s2 = "World"

Escape Sequences

Sequence Description
\n Newline
\t Tab
\\ Backslash
\" Double quote
\' Single quote

Formatted Output

Use %-formatting for dynamic strings:

name = "Alice"
age = 30
print("Name: %s, Age: %d" % (name, age))

# Zero-padded numbers
year, month, day = 2022, 1, 7
print("%d-%02d-%02d" % (year, month, day))  # 2022-01-07

Common format specifiers:

Specifier Usage
%d Integer
%f Floating-point
%s String
%x Hexadecimal integer

Tags: python Computer Architecture pycharm PEP8 Data Types

Posted on Tue, 30 Jun 2026 17:49:34 +0000 by groovey