Write a Python program to append the same value /a list multiple times to a list/list-of-lists

  • برمجة
  • برمجة بايثون

Write a Python program to append the same value /a list multiple times to a list/list-of-lists

الأجوبة

print("Add a value(7), 5 times, to a list:")
nums = []
nums += 5 * ['7']
print(nums)
nums1 = [1,2,3,4]
print("\nAdd 5, 6 times, to a list:")
nums1 += 6 * [5]
print(nums1)
print("\nAdd a list, 4 times, to a list of lists:")
nums1 = []
nums1 += 4 * [[1,2,5]]
print(nums1)
print("\nAdd a list, 4 times, to a list of lists:")
nums1 = [[5,6,7]]
nums1 += 4 * [[1,2,5]]
print(nums1)
هل كان المحتوى مفيد؟

تبحث عن مدرس اونلاين؟

محتاج مساعدة باختيار المدرس الافضل؟ تواصل مع فريقنا الان لمساعدتك بتأمين افضل مدرس
ماهو التخصص الذي تبحث عنه؟
اكتب هنا...