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

2

What is the difference between string and character ?

For example:

print 'Olá, mundo!'

print "Olá, mundo!"

Being both in theory are the same, right?

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

When I use the double quotation marks, one color and single quotation marks changes. But only that runs normally.

    
asked by anonymous 24.08.2017 / 23:41

1 answer

4

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

If you're comparing with C or other similar languages that uses apostrophes to delimit type char and quotes to delimit strings , then in Python this does not make sense, both notations are the same and can be used freely as long as they follow the pair, can not open with and try to close with another. This is useful for using the delimiter character itself within a string without having to escape it.

    
24.08.2017 / 23:50