Solved

# Python

Posted on 2011-09-15
222 Views
Noob here,

Do you know how I can get (search/find/ ?) the middle character of a string ?
0
Question by:Stephen1991
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 2

LVL 5

Accepted Solution

-Richard- earned 20 total points
ID: 36543067
s = "SomeString"
midChar = s[len(s)/2]

No searching is required - the "middle character" can be determined just by calculation.
0

Author Comment

ID: 36543092
Wow.  That was awesome.
0

Author Closing Comment

ID: 36543093
Thank you.
0

LVL 29

Expert Comment

ID: 36545580
It is better to use the // operator, i.e. midChar = s[len(s)//2].  It is the floored quotient also known as integer division.
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

### Suggested Solutions

The really strange introduction Once upon a time there were individuals who intentionally put the grass seeds to the soil with anticipation of solving their nutrition problems. Or they maybe only played with seeds and noticed what happened... Som…
Flask is a microframework for Python based on Werkzeug and Jinja 2. This requires you to have a good understanding of Python 2.7. Lets install Flask! To install Flask you can use a python repository for libraries tool called pip. Download this f…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
###### Suggested Courses
Course of the Month7 days, 6 hours left to enroll