[Python] Underscore Usage
I'll post about the underscore(_) in Python. Basic Usage Previous Value If you use underscore in REPL, it points to the previous result. >>> 3 + 5 8 >>> _ 8 >>> _ + 7 15 Ignoring Value You can use underscore for ignoring values. a, _, b = (1, 2, 3) print(f"{a}, {b}") # 1, 3 a, *_, b = (1, 2, 3, 4, 5, 6, 7) print(f"{a}, {b}") # 1, 7 If you use underscore in a loop, it indicates the current value ..
2021. 4. 26.
[Python] 3 Ways of Formatted String
There are 3 ways to write a formatted string in Python3. Let's check it one by one. Formatted String with Placeholder This method seems like a C language. It uses string-formatting operator %. print("String: %c, %s" % ('h', 'python')) # String: hello, python print("Integer: %d, %i" % (3, 7)) # Integer: 3, 7 print("Floating: %f, %F, %3.2f" % (2.818, 1.414, 3.14159)) # Floating: 2.818000, 1.414000..
2021. 1. 22.
[Python] List (Array) Data Structure
List is a data structure like Array. Elements in the List can be duplicated. Creating List ### [] method emptyList = [] weekdayList = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri'] nameList = ['Kim', 'Lee', 'Park', 'Kim'] ### list() function emptyList = list() testList = list('cat') # from String print(testList) # ['c', 'a', 't'] testTuple = ('red', 'green', 'blue') testList = list(testTuple) # from Tuple ..
2020. 12. 7.