Featured Post

Python Set Operations Explained: From Theory to Real-Time Applications

Image
A  set  in Python is an unordered collection of unique elements. It is useful when storing distinct values and performing operations like union, intersection, or difference. Real-Time Example: Removing Duplicate Customer Emails in a Marketing Campaign Imagine you are working on an email marketing campaign for your company. You have a list of customer emails, but some are duplicated. Using a set , you can remove duplicates efficiently before sending emails. Code Example: # List of customer emails (some duplicates) customer_emails = [ "alice@example.com" , "bob@example.com" , "charlie@example.com" , "alice@example.com" , "david@example.com" , "bob@example.com" ] # Convert list to a set to remove duplicates unique_emails = set (customer_emails) # Convert back to a list (if needed) unique_email_list = list (unique_emails) # Print the unique emails print ( "Unique customer emails:" , unique_email_list) Ou...

How to Create an Array and Its Types in Python

Python supports various array types. Here is a list of arrays and how to create examples for your reference. 

What is an array?


Python array is a class that mimics the array type of other languages and offers efficiency in storage, exchanging that for flexibility.

How to create an array


Here is the syntax to create an array:

data = array('f', [12.8, 5.4, 8.0, 8.0, 9.21, 3.14])


It creates an array of 6 floating point numbers; the type is indicated by the 'f' as the first parameter to the constructor. This concept is unlike the Python norm of types being dynamic and malleable. An array is an array of one kind of thing, and an array can only hold a restricted set of types.


Array types

Types of arrays

Here is a list of arrays:

'b' A C++ char type
'B' A C++ unsigned char type
'i': A C++ int type
'l': A C++ long type
'f': A C++ float type
'd': A C++ double type

What is an array type?

Arrays are class objects and are provided in the built-in module array, which must be imported:

from array import array

An array is a sequence type and has the basic properties and operations that Python provides for all sequence types. Array elements can be assigned to and can be used in expressions, and arrays can be searched and extended like other sequences.

Tips: I have referred some best books and Udemy course. I am giving here for your ready reference. The best Udemy course is Python Bootcamp and the best Python book is Python pocket primer.
Ads

Comments

Popular posts from this blog

SQL Query: 3 Methods for Calculating Cumulative SUM

Big Data: Top Cloud Computing Interview Questions (1 of 4)

5 SQL Queries That Popularly Used in Data Analysis