DEV Community

Cover image for Python notes #1 (General)
Alvin Seyidov
Alvin Seyidov

Posted on • Edited on

Python notes #1 (General)

List = []

squares = [x**2 for x in range(5)]
Enter fullscreen mode Exit fullscreen mode

squares = [x**2 for x in range(5)]
An ordered, mutable collection of elements.

Methods

append(x) → Add at the end.

insert(i, x) → Add at index i.

extend(iterable) → Concatenate another list.

pop([i]) → Remove and return element at i (default last).

remove(x) → Remove first occurrence of x.

clear() → Remove all elements.

Check Existence: x in my_list

Sort: my_list.sort() or sorted(my_list)

Reverse: my_list.reverse()

Count: my_list.count(x)

Index of Element: my_list.index(x)

Copy: my_list.copy()

len(my_list) → Length of list.

max(my_list), min(my_list) → Largest/smallest element.

sum(my_list) → Sum of elements (for numeric lists).

squares = [x**2 for x in range(5)]

List comprehension squares = [x**2 for x in range(5)]

csdf

sdfv

sdfv

sdfv

sdfv

sdfv

sdfv

sdfv

dsfv

Top comments (0)

Qodo Takeover

Introducing Qodo Gen 1.0: Transform Your Workflow with Agentic AI

Rather than just generating snippets, our agents understand your entire project context, can make decisions, use tools, and carry out tasks autonomously.

Read full post

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay