0% found this document useful (0 votes)
2 views2 pages

Python Programming Basics Cheat Sheet

This document provides a comprehensive overview of Python programming basics, including its design philosophy, variable creation, and basic data types. It covers essential data structures such as lists, tuples, dictionaries, and sets, as well as control flow statements and functions with error handling. The document serves as a reference and cheat sheet for Python syntax and programming concepts.

Uploaded by

sojey62677
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views2 pages

Python Programming Basics Cheat Sheet

This document provides a comprehensive overview of Python programming basics, including its design philosophy, variable creation, and basic data types. It covers essential data structures such as lists, tuples, dictionaries, and sets, as well as control flow statements and functions with error handling. The document serves as a reference and cheat sheet for Python syntax and programming concepts.

Uploaded by

sojey62677
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Python Programming Basics

Comprehensive Reference & Syntax Cheat Sheet

1. Introduction & Overview


Python is an interpreted, high-level, general-purpose programming language. Its design philosophy
emphasizes code readability through the use of significant indentation and clean, expressive syntax.

2. Variables and Basic Data Types


Variables in Python are created dynamically when you assign a value to them. Python automatically infers the
data type based on the value provided.

# Integer and Float


age = 28
price = 19.99

# String
name = "Alex"

# Boolean
is_active = True

3. Data Structures
Python provides built-in collection types designed to store grouped data efficiently:

Type Description Syntax Example

fruits = ["apple", "banana",


List Ordered, mutable sequence
"cherry"]

Tuple Ordered, immutable sequence coordinates = (10.0, 20.0)

Key-value pairs (ordered in Python


Dictionary user = {"name": "Alex", "age": 28}
3.7+)

Set Unordered collection of unique items unique_ids = {101, 102, 103}

4. Control Flow
Control flow statements direct the execution of code based on logic, conditional evaluations, and iterations.
Conditional Statements

score = 85

if score >= 90:


print("Grade: A")
elif score >= 80:
print("Grade: B")
else:
print("Grade: C")

Loops

# For Loop
for item in ["apple", "banana", "cherry"]:
print(item)

# While Loop
count = 0
while count < 3:
print(count)
count += 1

5. Functions & Error Handling


Functions modularize code into reusable units. Exception handling with try-except blocks gracefully
catches runtime errors.

def divide_numbers(a, b):


try:
result = a / b
return result
except ZeroDivisionError:
return "Error: Cannot divide by zero."

print(divide_numbers(10, 2)) # Output: 5.0

Python Programming Reference Guide — Page 1

You might also like