🐍 Core Python Commands (with Explanation)
🐍 Core Python Commands (with Explanation)
🔹 Create a List
my_list = ["item1", "item2"]➡️ A list is used to store multiple items in one variable.
➡ Items are written inside square brackets [ ] and separated by commas.
🔹 Add an Element to a List
my_list.append("new_item")➡️ The append() function adds a new item to the end of the list.
➡ The original list will be updated.
🔹 Remove an Element (by value)
my_list.remove("item2")➡️ The remove() function deletes an item from the list.
➡ It removes the first matching value it finds.
🔹 Print Output
print("Hello, world!")➡️ print() is used to display output on the screen.
➡ It is useful for showing results or messages.
🔹 Write a Comment
# This is a comment➡️ Comments are notes written for humans to read.
➡ Python ignores comments when running the code.
🔹 Get Length of List or String
length = len(my_list)➡️ len() tells you how many items are in a list
➡ It can also count the number of characters in a string.
🔹 Traverse a List (Loop)
for item in my_list:
print(item)➡️ A loop goes through each item in the list one by one.
➡ This is useful when you want to perform the same action for every item.