Python樹林– category –
-
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... -
Python樹林
How to Use the len() Function to Count Elements in a Python List
When working with lists in Python, you often need to know how many data items (elements) are stored in the list. For example, you might need to know how many times to run a for loop, or check if a list is empty (has 0 elements). Python p... -
Python樹林
Python Nested Lists: How to Create, Access, and Update
Python lists can contain not only numbers and strings but also other lists as elements. This structure, where a list is inside another list, is called a "Nested List". Nested lists are very useful for representing 2-dimensional grids (ma... -
Python樹林
How to Update Python List Elements: Assignment by Index
Python lists are a "mutable" (changeable) data type. This means that even after creating a list, you can freely change the values of its contents (elements). This operation is essential when updating the status of data retrieved from a d... -
Python樹林
Python Slicing Syntax: Master List Extraction with [start:stop:step]
Python lists are a powerful data type for storing ordered data. While you can access a single element using [0], Python also allows you to extract a range of elements to create a new list, such as "from the 1st to the 3rd element." This ... -
Python樹林
Creating Python Lists (list): Basic Usage of [] and list()
The list in Python is a very powerful and flexible data type that allows you to store multiple pieces of data in a specific order. Each piece of data (element) stored in a list can be changed, added, or deleted later (this property is ca... -
Python樹林
Python Raw Strings (r”…”): How to Disable Backslash Escapes
When handling strings in Python, the backslash (\) has a special meaning as an "escape sequence." For example, \n is interpreted as a newline, and \t as a tab. While this feature is useful, it becomes inconvenient when you want to treat ... -
Python樹林
String Concatenation in Python: Using the + Operator, f-strings, and join()
In Python, you often need to combine multiple strings into a new one. Examples include combining a first and last name to create a full name, or assembling a log message. There are several ways to concatenate strings, such as the + opera... -
Python樹林
Python Escape Sequences: How to Use \n (Newline), \t (Tab), and \ (Backslash)
In Python, strings are enclosed in single quotes (') or double quotes ("). However, sometimes you want to include the quote itself within the string (like "It's"), or insert special control characters like newlines or tabs. Writing them ... -
Python樹林
Python String (str) Type: Basics, Quotes, and Multi-line Strings
In Python, the string (str) is one of the most frequently used data types. It is used to handle text data such as greetings like "Hello", user IDs, filenames, or error messages. A string is treated as a "sequence of characters." This art... -
Python樹林
Handling Infinity (inf) and Not a Number (nan) in Python: float and math module
Python's float type can represent special states like "Infinity" and "Not a Number" in addition to standard numbers like 3.14 or -0.5. These are used in mathematical calculations (like division by zero attempts) or when handling missing ... -
Python樹林
Python Floating Point (float) Type: Basics, E-notation, and Calculation Errors
In Python, besides integers (int) like 10 or -5, we often need to handle numbers with decimal points like 3.14 or 0.5. These are called Floating Point Numbers (float).float is essential for many programming tasks, such as scientific calc... -
Python樹林
Python Boolean Operators: Usage of and, or, not and Short-Circuit Evaluation
When handling conditional branches like if statements in Python, you often want to combine multiple conditions. For example, "User is authenticated AND is an administrator" or "Process failed OR timed out." To achieve this, Python provid... -
Python樹林
Python Chained Comparison Operators: How to use a < b < c
When writing programs in Python, we often want to check if a value is within a specific range. For example, "Is the score 80 or more AND less than 100?" In many programming languages, you must use the and operator to write this logic: (8... -
Python樹林
Python Comparison Operators: The 6 Basics and How to Use Them
When using if statements to control the flow of a program, you often need to compare the relationship between two values. For example, "Is the variable greater than 100?" or "Does the input password match the saved one?" Comparison opera...