473,406 Members | 2,954 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,406 software developers and data experts.

string questions

Hi everyone, I'm a beginning programming student in Python and have a
few questions regarding strings.

If s1 = "spam"

If s2 = "ni!"

1. Would string.ljust(string.upper(s2),4) * 3 start it at the left
margin and move it 12 spaces to the right because of the 4 *3? If so,
why is it in the parathesis for the upper command and not the ljust? I
already know that it would cap it to NI!

2. To get the output "Spam Ni! Spam Ni! Spam Ni!" I could do something
like this string.join ([s1, s2]),

But I'm a little lost how to get it repeated three times on one line.
Would I just have to put the same command on the next two lines?

3. To change spam to spm, the string.replace seems to be the best
function to use. However, when I use
string.replace(s1, "a", " ") in python to replace a with an empty space,
it doesn't work...I just get spam back when I print s1. Any ideas?

Thanks.

-Shawn
Sep 15 '07 #1
1 1338
Marc 'BlackJack' Rintsch wrote:
But please don't use the functions in `string` that are also available as
methods on strings. Those functions are deprecated.

Meaning (for newbie clarification):

instead of string.upper(s2), just do s2.upper(). For more detail, see
the docs.

Sep 16 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Robert | last post by:
Hello, Can anyone help with this code? I need to split a long piece of text from a textarea box into small chunks, then POST these chunks to my credit-card provider, whereupon he will POST...
6
by: lkrubner | last post by:
Last year I asked a bunch of questions about character encoding on this newsgroup. All the answers came down to using ord() in creative ways to try to make guesses about multi-byte characters. I...
0
by: ani | last post by:
I have a questionaire page , which basically has questions with multiple choice answers. I need to accomplish paging on this and there are few questions that are gender specific. According the...
6
by: Nemok | last post by:
Hi, I am new to STD so I have some questions about std::string because I want use it in one of my projects instead of CString. 1. Is memory set dinamicaly (like CString), can I define for...
7
by: millerm | last post by:
I'm obviously new to C, and have been trying different things to get this done, but I'm at the end of the line and need some suggestions. I am reading a string in from a user, in the form of a...
14
by: Walter Dnes (delete the 'z' to get my real address | last post by:
I took a C course some time ago, but I'm only now beginning to use it, for a personal pet project. My current stumbling-block is finding an efficient way to find a match between the beginning of a...
6
by: Gidi | last post by:
Hi, I'm writing a C# Windows Application and i have 3 questions: 1. I have a string which i want to write into file but i want to write it in ASCII format, how can i do it? 2. I need my...
5
by: Mart | last post by:
Hi everybody, I plan to have a LOT of SQL string in my app. So I need your advice for this. Is it a good idea to store all my SQL string in the app.config file? For a maintenance point of...
4
by: Harro de Jong | last post by:
(absolute beginner here, sorry if this seems basic) Section 7.10 of 'How to Think Like a Computer Scientist' contains this discussion of string.find and other string functions: (quote) We can...
28
by: pradeep | last post by:
Hello friends: I know some people here don't like to answer C++ questions, but I believe this is really about the underlying C code. Anyway I have posted as well to the other group someone...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.