mori– Author –
-
Python樹林
Python while Loops: Repeating Actions While a Condition is Met
When performing repetitive tasks in Python, the for loop is suitable when you know the "number of elements in a list" or a "specific number of iterations." On the other hand, there are cases where the number of iterations is not fixed, b... -
Python樹林
Python Dictionary Comprehensions: How to Create and Manipulate Dictionaries Efficiently and Concisely
Just like List Comprehensions, Python has a feature called "Dictionary Comprehension" for efficiently generating and processing dictionaries (dict). Compared to creating a dictionary using a standard for loop, this method reduces the amo... -
Python樹林
Python List Comprehensions: Efficient List Creation in One Line
Python has a feature called "List Comprehensions" that allows you to concisely create a new list based on an existing list (or other iterables). This is one of Python's key features. Compared to using a standard for loop with append(), t... -
Python樹林
Python’s zip() Function: How to Loop Through Multiple Lists Together and Caveats
When programming, you often encounter situations where related data is stored in separate lists, such as a "list of names" and a "list of ages," and you want to retrieve and process them simultaneously. While you could access them using ... -
Python樹林
Looping a Set Number of Times in Python: Using the range() Function
In programming, regardless of the number of elements in a list, there are times when you want to execute a loop a specific number of times, such as "I want to repeat a process only 5 times" or "I want to retry 10 times." In Python, you c... -
Python樹林
Python for Loops: Basics of Looping Through Lists and Iterables
In programming, we frequently encounter situations where we want to apply the same process sequentially to a collection of data (such as a list or tuple). Python allows you to write these repetitive tasks concisely using the for statemen... -
Python樹林
Python Ternary Operator (Conditional Expression): How to Write if-else in One Line
In programming, we frequently encounter situations where we want to change the value assigned to a variable based on a specific condition. Usually, we use if and else statements, but Python provides a syntax to write this concisely in a ... -
Python樹林
Python Conditional Branching: Multiple Conditions with if, elif, and else
When creating a program, you often need branching logic like "If A, execute Process 1; otherwise, if B, execute Process 2; otherwise, execute Process 3." In Python, you can handle such complex conditional branches by combining if stateme... -
Python樹林
Truth Value Testing in Python: True/False Evaluation Rules for Each Data Type
In Python's if and while statements, you can evaluate not only the bool type (True/False) but also any object such as numbers, strings, and lists. Python has a basic rule: "Empty objects or zero are regarded as False, and everything else... -
Python樹林
Introduction to Python if Statements: Writing Conditionals and Indentation Rules
In programming, we frequently encounter situations where we want to execute code only if a specific condition is met. For example, "Add an item to the cart only if it is in stock" or "Display 'Pass' only if the score exceeds the passing ... -
Python樹林
Introduction to Python’s bytes Type: Creating and Handling Binary Data
In Python, the string type (str) handles Unicode characters. However, when dealing with image files, audio data, or network communication packets, you need raw binary data. The bytes type is used to represent this binary data. The bytes ... -
Python樹林
Deleting Elements from Python Dictionaries: How to Use del, pop(), and clear()
Python dictionaries (dict) provide several methods for removing unneeded data. You need to select the appropriate method depending on your goal: deleting a specific key, deleting and reusing a value, or resetting the entire dictionary. T... -
Python樹林
Checking Existence in Python Dictionaries: Using the in Operator for Keys, Values, and Pairs
When using Python dictionaries (dict), you frequently need to determine if a specific key is registered or if a specific value exists. For example, you might want to check if a specific setting exists in a configuration file or if a spec... -
Python樹林
Getting All Elements from a Python Dictionary: Usage of keys(), values(), items(), and List Conversion
When you want to access all data stored in a Python dictionary (dict), you might need a list of just the keys, want to aggregate just the values, or process keys and values as a set. Python provides three standard methods for these purpo... -
Python樹林
Adding and Updating Elements in Python Dictionaries: Assignment by Key
Python dictionaries (dict) are "mutable" (changeable) objects. This means you can add new key-value pairs or change values associated with existing keys even after the dictionary is created. An interesting point is that Python uses the e... -
Python樹林
Getting Values from Python Dictionaries: Using [] vs .get()
To use data stored in a Python dictionary (dict), you need to retrieve the "Value" by specifying the corresponding "Key". There are two main ways to do this: the basic method using square brackets [], and the safer method using the .get(... -
Python樹林
Creating Python Dictionaries (dict): 3 Basic Methods using {} and dict()
The Python Dictionary (dict) is a very important data type that stores data in Key-Value pairs. You use it to associate a value like "Tanaka" with a key like "name", or a value 101 with a key "id". While lists manage data using indices (... -
Python樹林
Python Set Operations: How to Use union, intersection, and difference
Python's set type does not just store unique elements; it also provides powerful methods for Set Operations (Logical Operations), just like in mathematics. Union: All elements from both sets (no duplicates). Intersection: Elements common... -
Python樹林
Checking if an Element Exists in a Python Set (Using the in Operator)
Besides not allowing duplicate elements, Python's set has another very important advantage: it can very quickly check if a specific element exists in the set. While lists can do the same thing, sets are overwhelmingly faster at checking ... -
Python樹林
Removing Elements from a Python Set: Differences Between remove, discard, and clear
Python sets are "mutable," meaning you can freely delete elements even after creating the set. There are several ways to delete elements, but it is important to understand the difference between .remove() and .discard(). There is also .c... -
Python樹林
Adding Elements to Python Sets: How to Use the .add() Method
Python's set is a "mutable" (changeable) data type, meaning you can add or remove elements even after creating it. Unlike lists, which use .append(), sets use the .add() method to add elements. This article explains the basic usage of th... -
Python樹林
Python Sets (set): Removing Duplicates and Basic Creation
In addition to lists and tuples, Python has a collection type called Set (set) for handling groups of data. Based on the mathematical concept of sets, the set type has two very important characteristics: No Duplicate Elements: If you try... -
Python樹林
Python’s range() Function: How to Generate Consecutive Number Sequences
When programming in Python, we often encounter situations where we want to run a for loop "only 5 times" or get "consecutive numbers from 10 to 20". This is where the range() function comes in. range() is not a list itself, but an object... -
Python樹林
How to Swap Variables in Python: Multiple Assignment Without Temporary Variables
In programming, there are times when you want to swap the values stored in two variables. For example, when implementing sorting algorithms. Traditional Method (Using a Temporary Variable) In many programming languages, you need a third ... -
Python樹林
Unpacking in Python: How to Assign List and Tuple Elements to Variables
When handling lists or tuples in Python, you often want to extract their elements into individual variables. For example, handling coordinate data usually involves accessing indices like this: point = (100.5, 35.2) # Normal index referen... -
Python樹林
Tuple Operations in Python: Indexing, Slicing, and Getting Length
Python tuples are an "immutable" data type, meaning you cannot change their contents once created. However, just because you cannot "change" them doesn't mean you can't use them. Just like lists, you can freely "access" elements, "slice"... -
Python樹林
What is a Python Tuple? Basic Usage and Differences from Lists
Python has several data types for managing collections of data. Among them, the tuple is very similar to a list, but there is one decisive difference. That is, tuples are "immutable" (unchangeable), meaning their contents cannot be chang... -
Python樹林
Python Lists: How to Find Element Position with .index()
When working with Python lists, you often need to know "where (at which index) a specific element is located." For example, checking "what number in the list corresponds to the 'admin' permission." For such searches, use the list's .inde... -
Python樹林
Deleting Elements from Python Lists: Differences and Usage of del, remove, and pop
Since Python lists are mutable (changeable), you can delete elements you no longer need. There are three main ways to delete elements. You need to choose the right one based on "which element you want to delete" (by position or value) an... -
Python樹林
Adding Elements to Python Lists: Using append() vs. insert()
Since Python lists are mutable (changeable), you can freely add or insert elements even after creating them. There are two basic methods for adding elements: append() and insert(). While they are similar, the difference lies in where the...