Python Basic
A concise introduction to Python fundamentals.
Python Installation
Follow the installation instructions in the Environment section:
https://cityuseattle.github.io/docs/environment/python/
Variables
Variables store data values. A variable is created when you assign a value to it. Rules for Python variable names:
- Must start with a letter or underscore
- Cannot start with a number
- Can contain letters, numbers and underscores (A–Z, 0–9, _)
- Are case-sensitive
Example:
message = "Hello World"
Multiple assignments
a, b, c = 5, 3.2, "Hello"
x = y = z = "Python"
Data types
Common Python data types: Integer, Float, Complex, Boolean, String, List, Tuple, Dictionary.
Numeric
Examples:
x = 5 # integer
y = 2.5 # float
z = 2 + 3j # complex (use 'j' for the imaginary unit)
Boolean
print(10 > 9) # True
Sequence types (string, list, tuple)
message = "This is a string"
lst = ['physics', 'chemistry', 1997, 2000]
tup = ('physics', 'chemistry', 1997, 2000)
Dictionary
students = {1: "Steve", 2: "Bill", 3: "Ram"}
String functions
message = "this is also a string"
print("Title:" + message.title())
print("Uppercase: " + message.upper())
print("Lowercase: " + message.lower())
Concatenation (f-strings)
first_message = "Hi!"
second_message = "How are you?"
full_message = f"{first_message} {second_message}"
print(full_message)
Numbers and operators
Python supports arithmetic, comparison, assignment, logical, bitwise, membership and identity operators. See the full tutorial pages in the repo for expanded examples and images.
If you want the complete original tutorial text copied verbatim into this top-level page (images and all examples), tell me and I will paste it here.