Solved

Python

Posted on 2011-09-15
4
222 Views
Last Modified: 2012-05-12
Noob here,

Do you know how I can get (search/find/ ?) the middle character of a string ?
0
Comment
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
  • Learn & ask questions
  • 2
4 Comments
 
LVL 5

Accepted Solution

by:
-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

by:Stephen1991
ID: 36543092
Wow.  That was awesome.  
0
 

Author Closing Comment

by:Stephen1991
ID: 36543093
Thank you.
0
 
LVL 29

Expert Comment

by:pepr
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question