Posts

Showing posts with the label native

Featured Post

Python map() and lambda() Use Cases and Examples

Image
 In Python, map() and lambda functions are often used together for functional programming. Here are some examples to illustrate how they work. Python map and lambda top use cases 1. Using map() with lambda The map() function applies a given function to all items in an iterable (like a list) and returns a map object (which can be converted to a list). Example: Doubling Numbers numbers = [ 1 , 2 , 3 , 4 , 5 ] doubled = list ( map ( lambda x: x * 2 , numbers)) print (doubled) # Output: [2, 4, 6, 8, 10] 2. Using map() to Convert Data Types Example: Converting Strings to Integers string_numbers = [ "1" , "2" , "3" , "4" , "5" ] integers = list ( map ( lambda x: int (x), string_numbers)) print (integers) # Output: [1, 2, 3, 4, 5] 3. Using map() with Multiple Iterables You can also use map() with more than one iterable. The lambda function can take multiple arguments. Example: Adding Two Lists Element-wise list1 = [ 1 , 2 , 3 ]

Python Supports These 5 Native Data types

Image
Python supports five native data types. The Data types are such that a Programmer can use to write the logic and get the output. Many beginners may not aware of native data types. So I am adding a short note on that here. Native means as is Python supported data types. Python Five Key Native Data Types Python Native Data Types In Python, you can find five types of native data types. Here is a quick list for you. Those are Number, String, List, Tuple, Set, and Dictionary. 1. Number For all the numeric values,  you can use this data type. 2. String It handles all Characters, Special-symbols, and Alphanumeric values. 3. List It is something like sequential data. A program can do Sort, Merge, etc. on this data. 4. Tuple Data is a little different from the List. 5. Set This kind of Data-type helps you to do set operations. Those are like Intersection, Difference, etc. 6. Dictionary Here, the Dictionary something like a group of List kinds of data. But, each value has a key associated with i