Solved

Python

Posted on 2011-09-15
4
213 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 28

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Python Script 1 75
Merging two data frames and doing calculation 5 56
regex to extract ip:john 17 69
Ptyhon Dex.txt how to use this regex for this python script? 40 82
Here I am using Python IDLE(GUI) to write a simple program and save it, so that we can just execute it in future. Because when we write any program and exit from Python then program that we have written will be lost. So for not losing our program we…
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 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 if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …

895 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now