Newbie to Python big problems

A forum for general discussion of the Python programming language.

Newbie to Python big problems

Postby darksider9 » Tue Apr 09, 2013 11:04 pm

Hi All,

First time poster here, and newbie to Python. I am currently working on a script that will decode something for me. So the long and short of my problem/question is how do I print a character from a specific position? Something like below:

##What the script will be looking through
Please use code tags when you post code like it has been edited below, Thanks

Code: Select all
str = 'ahgaofihoibjgointu24bfew8yb89'
find_o = str.find('o')
print find_o

should print:

This is because it simply prints the position the character it is looking for. What I am looking for is I tell it to "print find_o" and it prints the character in the fourth position. Does anyone know how I can achieve this? Thank you in advance.

Posts: 1
Joined: Tue Apr 09, 2013 10:56 pm

Re: Newbie to Python big problems

Postby Yoriz » Tue Apr 09, 2013 11:19 pm

You shouldn't use str as a variable name as it is a python keyword use string instead.
to get a character from a specific position in a string you can do the following.

Code: Select all
string = 'ahgaofihoibjgointu24bfew8yb89'
find_o = string.find('o')
print find_o

print string[find_o]

Ps please read the following post
New Users, Read This
Join the #python-forum IRC channel on!
User avatar
Posts: 1574
Joined: Fri Feb 08, 2013 1:35 am
Location: UK

Re: Newbie to Python big problems

Postby StormJedi » Tue Apr 09, 2013 11:19 pm

Hello and welcome to the forums!
I strongly recommend you read this: viewtopic.php?f=10&t=145

And try this code:
Code: Select all
str = 'ahgaofihoibjgointu24bfew8yb89'

That may be what you are looking for, I found this problem on StackOverflow ... -character
Python 2.7
Python 3.3
Windows 7 x64
Ubuntu 12.10 x64
One day I hope to use one OS and 1 Python flavor, until that day, life goes on.
Posts: 27
Joined: Fri Feb 22, 2013 3:36 pm

Return to General Discussions

Who is online

Users browsing this forum: No registered users and 6 guests