TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

Python List reverse() method with Examples

Python List reverse() method with Examples on append(), clear(), extend(), insert(), pop(), remove(), index(), count(), pop(), reverse(), sort(), copy(), all(), bool(), enumerate(), iter(), map(), min(), max(), sum() etc.

<< Back to PYTHON

Python List reverse() Method

Python reverse() method reverses elements of the list. If the list is empty, it simply returns an empty list. After reversing the last index value of the list will be present at 0 index. The examples and method signature is given below.

Signature

reverse()

Parameters

No parameter

Return

It returns None.

Let's see some examples of reverse() method to understand it's functionality.

Python List reverse() Method Example 1

Let's first see a simple example to reverse the list. It prints all the elements in reverse order.

# Python list reverse() Method
# Creating a list
apple = ['a','p','p','l','e']
# Method calling
apple.reverse() # Reverse elements of the list
# Displaying result
print(apple)

Output:

['e', 'l', 'p', 'p', 'a']

Python List reverse() Method Example 2

It returns empty list if the list is the list is empty. See the example below.

# Python list reverse() Method
# Creating a list
apple = []
# Method calling
apple.reverse() # Reverse elements of the list
# Displaying result
print(apple)

Output:

[]

Python List reverse() Method Example 3

This example demonstrate that after reversing order of element does not change.

# Python list reverse() Method
# Creating a list
apple = ['e', 'l', 'p', 'p', 'a']
apple2 = ['a', 'p', 'p', 'l', 'e']
# Calling Method
apple.reverse()
# Comparing both lists
if apple == apple2:
    print("Both are equal")
else: print("Not equal")

Output:

Both are equal

Next TopicPython Lists




Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf