Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cover image for Append() function in Python.
Keshav Jindal
Keshav Jindal

Posted on

     

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)
Enter fullscreen modeExit fullscreen mode

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)
Enter fullscreen modeExit fullscreen mode

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']

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Hi, I'm Keshav. I am a tech enthusiast and have an interest in programming. I am good at JavaScript, Python, HTML, and CSS.
  • Location
    Haryana, India
  • Education
    Wisdom World School, Kurukshetra
  • Work
    Student
  • Joined

More fromKeshav Jindal

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp