What is the difference between "string" and "Character" in Python?

Asked

Viewed 2,087 times

3

What is the difference between the string and Character?

For example:

print 'Olá, mundo!'

print "Olá, mundo!"

Since the two in theory are the same thing, right?

PS.: I opened XML to do my color editing, and in Python XML comes a color for string and a color for Character.

When I use the double quotes gets a color and single quotes changes. But only that it rotates normally.

  • 1

    There are two strings.

  • I know there are two strings. Only in the python xml documentation, the command for string comes from a color, in case " " and Character comes with another color in case ' '.

  • From https://www.tutorialspoint.com/python/python_strings.htm Python does not support a Character type. So apparently Python doesn’t have a Character type, only string.

  • And the recommended in Python are simple quotes.

  • Um,,, got it! Thanks, and liked the site too.

  • Did the answer solve your question? Do you think you can accept it? See [tour] if you don’t know how you do it. This would help a lot to indicate that the solution was useful to you. You can also vote on any question or answer you find useful on the entire site.

  • Honestly, I don’t understand what he meant by "comes a color for string and a color for Character".

Show 2 more comments

1 answer

5

Pyhton doesn’t have the type char or something like that, it’s just strings, if you want to have a character just use a string that has only one character. If you want a number value that is equivalent to a character use a numeric type that stores the character table number.

If comparing to C or other similar languages that uses apostrophes to delimit the type char and quotes to delimit strings, So in Python this makes no sense, both notations are equal and can be used freely as long as they follow the pair, can’t open with and try to close with another. This is useful for using the delimiter character itself within a string without having to escape him.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.