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

difference between string and list

I'm having trouble figuring out the difference between a string and a
list.

I know that:
string = "foo bar"

is a list of characters, "foo bar", and string[0] is "f".

while:

list = ["foo", "bar"]
and list[0] is "foo".

strings have methods like string.count("f") returns 1. What methods do
lists have? Is it a similar class to string?

thanks,
Lincoln

Feb 27 '07 #1
2 11902
"lincoln rutledge" <li******@oar.netwrites:
strings have methods like string.count("f") returns 1. What methods do
lists have? Is it a similar class to string?
Strings and lists are similar but not the same. dir(string) will show
you the methods available for strings. dir(list) will show you the
methods available for lists. See also the "built-in types" section
of the Python Library Reference Manual, the section on sequence types.
Feb 27 '07 #2
lincoln rutledge a écrit :
I'm having trouble figuring out the difference between a string and a
list.
['R', 'e', 'a', 'l', 'l', 'y', ' ', '?', ' ', 'S', 'e', 'e', 'm', 's', '
', 'q', 'u', 'i', 't', 'e', ' ', 'o', 'b', 'v', 'i', 'o', 'u', 's', ' ',
't', 'o', ' ', 'm', 'e', '.']

I know that:
string = "foo bar"

is a list of characters
No. It's a string. Python doesn't have a "character" type.
>, "foo bar", and string[0] is "f".
Yes. And ?
while:

list = ["foo", "bar"]
and list[0] is "foo".
So ?
strings have methods like string.count("f") returns 1. What methods do
lists have?
Open your interactive Python interpreter and type
>>help(list)
Is it a similar class to string?
Not exactly. Both are sequences, that's all. FWIW, try this:

"foo"[0] = "b"

HTH
Feb 27 '07 #3

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

Similar topics

5
by: Richard | last post by:
Hi, Can anyone tell me what the difference is between for line in file.readlines( ): and for line in file:
18
by: John M. Gabriele | last post by:
I've done some C++ and Java in the past, and have recently learned a fair amount of Python. One thing I still really don't get though is the difference between class methods and instance methods. I...
6
by: roopa | last post by:
I have declared a class with name List; and in main() function, i have declared the List object as follows class List { public: List() { cout<<"In List Constuctor";
1
by: Deckarep | last post by:
Dear CSharp Group, Both of these techniques work as expected but what is the better way of doing this? Or does it even make a difference? Method 1: public delegate void MyDelegate(string...
9
by: Stephan Steiner | last post by:
Hi I seem to have a bit of trouble understanding one bit of how generics work: In C#, every class automatically derives from object, and inherits a bunch of properties (i.e. ToString()). Thus,...
12
by: Petronius | last post by:
Hallo, does anyone have an idea how to implement difference lists in Javascript? Thanks allot in advance
5
by: narutocanada | last post by:
hi what is the difference between the two kinds of brackets? I tried a few examples but I can't make out any real difference: lst = print lst print lst print lst lst = (10, 20, 30) print...
4
by: Tom P. | last post by:
What would the difference be between the following two: public class Foo : IList<string> { .... } public class Foo : List<string>
11
by: cmb3587 | last post by:
I have two arrays and I'm trying to create a 3rd array that is the difference between the two arrays Ex: arrayA: 3 5 8 9 arrayB: 3 4 6 9 difference of A-B: 5 8 however, my...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.