Monday, April 21, 2025

Generating e-mail Addresses with Python

list_e = ['michael', 'john', 'samantha']

domain = 'domain.com'

for x in list_e:
    print(x + '@' + domain)

This Python code creates a list of email names, and for each name in the list, it appends a domain name to the name to create a valid email address.

Here is a line-by-line explanation of the code:

list_e = ['michael', 'john', 'samantha']

This line creates a list named list_e that contains three string values, which are the names of the email recipients.

domain = 'domain.com'

This line assigns a string value of 'domain.com' to the variable domain, which will be used to append to the email names to create the full email address.

for x in list_e:
    print(x + '@' + domain)

This line starts a for loop that iterates over each element x in list_e. For each iteration, it concatenates the email name x with the domain name '@' + domain, using the string concatenation operator +. Finally, it prints the email address to the console.

The output of this script will be:

michael@domain.com
john@domain.com
samantha@domain.com

This is the email address list created by concatenating the name strings with the domain string.

No comments:

Post a Comment

Tkinter Introduction - Top Widget, Method, Button

First, let's make shure that our tkinter module is working ok with simple  for loop that will spawn 5 instances of blank Tk window .  ...