Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # def msg(message):
- # print(message)
- var_list = ['a', 'b', 'c', 'd', 'e']
- def func(inp):
- output = ""
- for item in inp:
- output += item
- return output
- a = "I'll "
- b = "have "
- c = "a "
- d = "cheese "
- e = "sandwich."
- # replacing values in a list
- print(func(map(eval, var_list)))
- print("----------------------------------------------")
- i = 0
- numbers = []
- print("The list now: ", numbers)
- while i < 6:
- print(f"Adding {i} to list")
- i = i + 1
- numbers.append(i)
- print("The list now: ", numbers)
- # end=' ' space after each output //there is no spacing after each letter in end=' '//
- print("\nThe numbers in the list: ")
- for num in numbers:
- print(num, end=', ')
- print("\n----------------------------------------------")
- # Convert a list to a string join() function,
- # but if the list contains integers then convert it into string and then use join()
- a = ["Geeks", "for", "Geeks"]
- # print the list using join function()
- print(' '.join(a))
- print("\n----------------------------------------------")
- # print the list by converting a list of
- # integers to string
- a = [1, 2, 3, 4, 5]
- print(str(a)[1:-1])
- # if list is not a string
- # Use map() to convert each item in the list to a string and join
- a = [1, 2, 3, 4, 5]
- print(' '.join(map(str, a)))
- # print "in new line"
- print('\n'.join(map(str, a)))
- print("\n-------------------------------------------------")
- a = 35
- a = str(a)
- total = (sum(int(x) for x in a))
- print(f"Sum = {total}")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement