Append() function in Python.

1.What is Append function?
Append function is used to add a item at the end of the sequence if the condition is True.

Example1

subjects = [‘Maths’,’Science’,’Physics’]
subjects.append(‘Chemistry’)
print(subjects)

Explanation:
Statement 1:
sub…


This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Keshav Jindal

1.What is Append function?
Append function is used to add a item at the end of the sequence if the condition is True.

Example1

subjects = ['Maths','Science','Physics']
subjects.append('Chemistry')
print(subjects)

Explanation:
Statement 1:
subjects = ['Maths','Science','Physics']
Statement 2:
append functions is being used in Statement 2 So, 'Chemistry' will be added at the end of the sequence.
Final Output:
['Maths', 'Science', 'Physics', 'Chemistry']

Example 2

list1=['Mathematics', 'AI', 'Science','Political Science']
list2=[]
for i in list1:
 if 'a' in i:
    list2.append(i)
print(list2) 

Explanation:
Iteration1:
"a" in 'Mathematics' , condition becomes True and it will be added at the end of list2.
Iteration1:
"a" in 'AI' , condition becomes FALSE and it will not be added in sequence.

Final output
['Mathematics', 'Political Science']


This content originally appeared on DEV Community 👩‍💻👨‍💻 and was authored by Keshav Jindal


Print Share Comment Cite Upload Translate Updates
APA

Keshav Jindal | Sciencx (2022-09-13T12:43:14+00:00) Append() function in Python.. Retrieved from https://www.scien.cx/2022/09/13/append-function-in-python/

MLA
" » Append() function in Python.." Keshav Jindal | Sciencx - Tuesday September 13, 2022, https://www.scien.cx/2022/09/13/append-function-in-python/
HARVARD
Keshav Jindal | Sciencx Tuesday September 13, 2022 » Append() function in Python.., viewed ,<https://www.scien.cx/2022/09/13/append-function-in-python/>
VANCOUVER
Keshav Jindal | Sciencx - » Append() function in Python.. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/09/13/append-function-in-python/
CHICAGO
" » Append() function in Python.." Keshav Jindal | Sciencx - Accessed . https://www.scien.cx/2022/09/13/append-function-in-python/
IEEE
" » Append() function in Python.." Keshav Jindal | Sciencx [Online]. Available: https://www.scien.cx/2022/09/13/append-function-in-python/. [Accessed: ]
rf:citation
» Append() function in Python. | Keshav Jindal | Sciencx | https://www.scien.cx/2022/09/13/append-function-in-python/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.