Join method in Python

 Join method in Python applied on a list of names:

mylist = ["abdur", "rehman", "qadeer", "cats", "dogs"]

oneLiner = " & ".join(mylist)
print(oneLiner)


The above code returns the following;

abdur & rehman & qadeer & cats & dogs


 Join method in Python applied on a list of numbers:

mylist = [str(i*7) for i in range(1, 11)]
mylist = [7, 14, 21, 28, 35, 42, 49, 56, 63, 70]
newlist ="\n".join(mylist)
print(newlist)

The above code returns the following;

7

14

21

28

35

42

49

56

63

70


Comments

Popular posts from this blog

Quotation marks to wrap an element in HTML

The Basic Structure of a Full-Stack Web App

Unlocking Web Design: A Guide to Mastering CSS Layout Modes