473,385 Members | 1,429 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to say for every character in a string

Well I have program in which i have look into every character of a string.
Is there a method in python

str = " the world is small"

for every char in str ( I don't know how to do this)
Jan 23 '08 #1
2 3023
Sorry got it. I am just new to python and still learning

Solution:

We just have to treat the string as array of characters so


for i in range (0,len(str))
print str[i]

will do fine
Jan 23 '08 #2
Smygis
126 100+
Sorry got it. I am just new to python and still learning

Solution:

We just have to treat the string as array of characters so


for i in range (0,len(str))
print str[i]

will do fine

NOOOOOOOOOOO! Now zeh worlt wil endet! Or maybe not ;)

You can iterate directly over the string instead.
Expand|Select|Wrap|Line Numbers
  1. worldString = " the world is small"
  2. for i in worldString:
  3.     print i
  4.  
And dont use str as a variable name. You will overwrite the str() function.

Expand|Select|Wrap|Line Numbers
  1. >>> str(666)
  2. '666'
  3. >>> str = "Hello"
  4. >>> str(666)
  5. Traceback (most recent call last):
  6.   File "<stdin>", line 1, in <module>
  7. TypeError: 'str' object is not callable
  8. >>> 
  9.  
It wont end the world but its a bad habit.
Jan 24 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

14
by: Charles L | last post by:
I don't know if this is a stupid quesiton or not. I would like to know how to convert an array of characters generated from a previous operation to a string ie how do I append a null character at...
7
by: teachtiro | last post by:
Hi, 'C' says \ is the escape character to be used when characters are to be interpreted in an uncommon sense, e.g. \t usage in printf(), but for printing % through printf(), i have read that %%...
40
by: findmadhav | last post by:
I need a program in C (something like a TSR) which will automatically press the function key F6, say about every 5 seconds. Can anyone provide me with an exe of such a program? Thanks in advance.
9
by: booksnore | last post by:
I am writing some code to search for strings that contain every letter of the alphabet. At the moment I am using the method below to check to see if a string contains every letter of the alphabet....
5
by: JrMc | last post by:
I am new to this .net environement. I'm needing to do a simple task - I need to read the first character of a word and replace it with an uppercase. Example: "horse" --> change to "Horse" ...
1
by: francescomoi | last post by:
Hi. I want to make a script which reads a file and shows its contents: ------------ using (StreamReader sr = new StreamReader(objResponse.GetResponseStream(),...
8
by: Brand Bogard | last post by:
Does the C standard include a library function to convert an 8 bit character string to a 16 bit character string?
15
by: wizardyhnr | last post by:
i want to try ANSI C99's unicode fuctions. so i write a test program. the function is simple, but i cannot compile it with dev c++ 4.9.9.2 under windows xp sp2, since the compiler always think that...
3
by: yawnmoth | last post by:
Say I had .a.b.c and wanted to return abc. Any ideas as to how I'd do this? Here's my attempt, but it doesn't work: <?php echo preg_replace('#(?:.(.))+#s', '$1', '.a.b.c'); ?> Any ideas?
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.