Python

Noob here,

Do you know how I can get (search/find/ ?) the middle character of a string ?
Stephen1991Asked:
Who is Participating?
 
-Richard-Commented:
s = "SomeString"
midChar = s[len(s)/2]

No searching is required - the "middle character" can be determined just by calculation.
0
 
Stephen1991Author Commented:
Wow.  That was awesome.  
0
 
Stephen1991Author Commented:
Thank you.
0
 
peprCommented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.