---
description: Use of step size
---

# Palindrome detection

![DNA](https://2417198446-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F04q6gn1bES1RZU067ZeW%2Fuploads%2Fgit-blob-3dbdaeefe9761e46d2a66c479c890452b8532a8d%2Fimage.png?alt=media)

There are some palindrome sequences in DNA, such as "ATGCGCGTAATGCGCGTA"

This sequence is symmetric from a certain position in the middle, and we call this sequence a palindrome sequence. So how to detect palindrome sequence?

Look at the following program:

```python
def palindrome(string):
    print(string, end='\t')
    print(string==string[::-1])
    # return string==string[::-1]

palindrome('123454321')
palindrome('13454321')
palindrome('ATGCGCGTAATGCGCGTA')
palindrome('ATGCGCGTAATGCGCGTG')
```

If this sequence is a palindrome sequence, then it will return True, if not, it will return False.

The string is reversed by changing the string step length to -1, and then it is judged whether it is the same as the previous string to distinguish the palindrome sequence.

```python
123454321	True
13454321	False
ATGCGCGTAATGCGCGTA	True
ATGCGCGTAATGCGCGTG	False
>>> 
```

## Statistics

Start time of this page: December 20, 2021

Completion time of this page: December 20, 2021
