Study Note54 Lambda function A lambda function, also known as an anonymous function or a lambda expression, is a concise way to define a small, one-line function in Python. Unlike normal functions, lambda functions are defined without a name and can have any number of parameters, but can only contain a single expression. The syntax for a lambda function is:lambda parameters: expressionHere, parameters are the input values t.. 2024. 4. 5. 10. Purpose of 'while' and 'for in' 1. `while` loop: - Executes a block of code repeatedly as long as a specified condition is true. - The condition is evaluated before each iteration, and if it's true, the loop continues. If it's false, the loop terminates. - Typically used when the number of iterations is not known beforehand. For example, the following code prints the numbers from 0 to 9 as long as `num` is less than 10: num = .. 2024. 4. 2. 9. Method vs Function / Dictionary vs List Method vs Function While studying Python, I try to organize the method of using . or. () through this post because I was confused about how to write . In Python, there are cases where you use a dot (.) when calling a function and cases where you don't. Here are the general rules: Method: When calling an object's method, you use a dot (.). For instance, when invoking the split() method of a strin.. 2024. 3. 28. 8. Function simplification Function simplification The reason for simplifying functions is to make the code more concise and readable. Simplified functions reduce redundant code, decrease unnecessary complexity, and enhance maintainability. Additionally, Simplified functions can improve performance and operate more efficiently. Here is an example of simplification Example 1 Before num = 3 if num % 2 == 0: result = 'even' .. 2024. 3. 27. 7. F-strings & Try Except F-strings f-strings provide a simple and intuitive way to format strings in Python, making it easier to read and maintain code. To use f-strings, simply prefix the string with 'f' or 'F' and place variable names or expressions inside curly braces {}. The contents within the curly braces are then replaced with the value of the respective variable or expression. F-strings allow variables to be ins.. 2024. 3. 27. 6. Set & tuples and list Set In Python, a set is a data type representing a collection of unique elements. Sets do not allow duplicate elements and are unordered. This makes sets useful for operations such as set union, intersection, and difference. Sets are defined using curly braces {}, with elements separated by commas. For example: my_set = {1, 2, 3, 4, 5} You can create a set from a list or tuple, removing any dupl.. 2024. 3. 27. 이전 1 ··· 4 5 6 7 8 9 다음