logo-MindMajix
PostPythonPython
M
Megha Sharma

Posted on 22nd June 2024|50 views

0
votes

How To Append Integer To The Beginning Of The List In Python?

Hi all,

I’m trying to make a list that begins with a variable and ends with an integer. So I tried writing ‘a+list’ but I found an error. Here, ‘a’ as an integer and thus I cannot use either extend or append. Can I get any suggestions that work in this case?

 

1 answers
Answers
P
Sowjanya Mishti

Posted on 22nd June 2024| views

Now the purpose why you saw the error because you are utilizing the variable name as the list which is not supported in Python, Python has a few reserved keywords that can not be utilized as the variable name therefore instead of that, you should utilize the below-mentioned method:-

l = 6

abc_list = [3, 2, 1]

print([l] + abc_list)

 

Write your answer

STILL GOT QUERIES?

Get a Live FREE Demo

  • Explore the trending and niche courses and learning maps
  • Learn about tuition fee, payment plans, and scholarships
  • Get access to webinars and self-paced learning videos
Name
Course *
Email *
Phone Number