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
Solved

Python

Posted on 2011-09-15
4
216 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
  • 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Dictionaries contain key:value pairs. Which means a collection of tuples with an attribute name and an assigned value to it. The semicolon present in between each key and values and attribute with values are delimited with a comma.  In python we can…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
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…

856 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