Append integer to beginning of list in Python

326    Asked by ranjan_6399 in Python , Asked on Apr 14, 2021

 I have an integer and a list. I would like to make a new list of them beginning with the variable and ending with the list. Writing a + list I get errors. The compiler handles as integer, thus I cannot use append, or extend either. How python list append to front?

Answered by Ranjana Admin

For appending an integer to the beginning of the list in Python we can use the following method mentioned below.

Now the reason why you were getting the error because you are using the variable name as the list that is not allowed in Python.


Python has some reserved keywords which can not be used as the variable name so instead of that, you should use the below-mentioned code for python list append to



Your Answer

Interviews

Parent Categories