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

list,py

The document provides a comprehensive guide on Python lists, covering their definition, properties, creation, and various operations such as accessing, updating, and slicing elements. It also includes information on list methods, looping techniques, list comprehension, exception handling, and comparisons with tuples. Additionally, it highlights real-world use cases and offers quick tips for interviews related to Python lists.

Uploaded by

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

list,py

The document provides a comprehensive guide on Python lists, covering their definition, properties, creation, and various operations such as accessing, updating, and slicing elements. It also includes information on list methods, looping techniques, list comprehension, exception handling, and comparisons with tuples. Additionally, it highlights real-world use cases and offers quick tips for interviews related to Python lists.

Uploaded by

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

from fpdf import FPDF

# Create PDF
pdf = FPDF()
pdf.add_page()
pdf.set_auto_page_break(auto=True, margin=15)
pdf.set_font("Arial", size=12)

# Content title and sections


title = "📝 Complete Python List Notes – Deep Dive"
sections = [
("1. What is a List?",
"A list is a mutable, ordered, and indexable collection in Python. "
"It can store heterogeneous (mixed) data types including numbers, strings,
booleans, other lists, and even functions or objects.\n"
"Example:\nmy_list = [1, \"hello\", 3.14, True, [5, 6]]"),

("2. Key Properties of a List",


"Ordered – Maintains insertion order (Python 3.7+)\n"
"Mutable – You can change, add, or delete items\n"
"Indexed – Supports both positive and negative indexing\n"
"Heterogeneous – Can hold mixed data types\n"
"Iterable – Can be looped over with for or comprehensions"),

("3. List Creation",


"a = []\nb = list()\nc = list(\"abc\")\nd = [1, 2, 3]\ne = [0] * 5\nf = [1,
[2, 3], [4, [5, 6]]]"),

("4. Accessing List Elements",


"l = ['a', 'b', 'c', 'd']\nprint(l[0]) → 'a'\nprint(l[-1]) → 'd'\
nprint(l[1:3]) → ['b', 'c']"),

("5. Updating List Elements",


"l[1] = 'z' → ['a', 'z', 'c', 'd']"),

("6. List Methods – Add/Insert/Remove",


"Add:\nl.append(3), l.insert(1, 'a'), l.extend([4,5])\n"
"Remove:\nl.remove(2), l.pop(0), del l[1], l.clear()"),

("7. Slicing Lists",


"l = ['a','b','c','d','e','f','g']\n"
"l[1:5], l[::-1], l[::2], l[-2:-6:-1]"),

("8. Looping Techniques",


"for i in l: print(i)\nfor i in range(len(l)): print(l[i])\nfor i, val in
enumerate(l): print(i, val)"),

("9. List Comprehension",


"squares = [x**2 for x in range(5)]\nevens = [x for x in range(10) if x % 2 ==
0]"),

("10. Exception Handling",


"IndexError – list index out of range\nValueError – remove/index value not
found\nTypeError – invalid operations"),

("11. List vs Tuple",


"Mutable: List ✅ / Tuple ❌\nSyntax: [ ] vs ( )\nPerformance: List is slower\
nUse-case: List for dynamic, Tuple for fixed"),
("12. Nested Lists",
"l = [[1, 2], [3, 4]]\nprint(l[1][0]) → 3"),

("13. Identity vs Equality",


"a is b – True (same object)\na == b – True (same content)\na is c – False
(copy)\na == c – True"),

("14. Memory Optimization Tip",


"Use generators or array module for large data sets over lists."),

("15. Real-World Use Cases",


"- Dynamic storage (cart, tasks)\n- Stack/Queue\n- Matrix\n- CSV/database
rows\n- Batch slicing"),

("✅ Interview Quick Crux",


"- Mutable, index-based, ordered\n- append() vs extend()\n- remove() vs pop()\
n- Slicing with steps\n"
"- Shallow vs Deep copy\n- List comprehension\n- Handle IndexError &
ValueError")
]

# Add content to PDF


pdf.set_font("Arial", 'B', 14)
pdf.multi_cell(0, 10, title)
pdf.ln()

pdf.set_font("Arial", size=12)
for header, content in sections:
pdf.set_font("Arial", 'B', 12)
pdf.multi_cell(0, 10, header)
pdf.set_font("Arial", size=12)
pdf.multi_cell(0, 10, content)
pdf.ln()

# Save PDF
pdf.output("Complete_Python_List_Notes.pdf")

You might also like