'ab' in 'xabx' True; 'ab' in 'xbax' False
msg = "what do you like?"
msg = 'what do you like?'
immutable strings, unlike C strings.
str() return a string version of object lib/stdtypes#str
Numerazione caratteri nella stringa
0 | 1 | 2 | 3 | 4 | index |
---|---|---|---|---|---|
-5 | -4 | -3 | -2 | -1 | index reverse |
R | o | b | i | n | word = "Robin" |
Strings can be indexed;
1° character of a string has index 0, like in C.
indices negative start counting from the right.
word = "Robin"
word[0] | 'R' | indexing. First element |
word[-1] | 'n' | indexing reverse. Last element |
word[-2] | 'i' | the last-but-one character |
word[1:4] | 'obi' | slicing, start point inclusive end point non-inclusive |
word[0:3] word[ :3] |
'Rob' | the first 3 |
word[-3: ] | 'bin' | the last 3 |
word[:-3] | 'Ro' | Everything except the last 3 |
word[-3:-1] | 'bi' | end point non-inclusive |
word[0:] word[:] |
'Robin' | |
s[:i] + s[i:] | equals s | concatenate |
word[i:i] | '' | stringa vuota |
len(word) | 5 |
escape sequence |
meaning |
---|---|
\n | ASCII line feed LF |
\r | ASCII carriage return CR |
\t | ASCII horizontal tab TAB |
\xhh | character with hexadecimal value hh |
reference/datamodel#the-standard-type-hierarchy
ord() | converts a Unicode code point from its string form
to an integer in the range 0 - 10FFFF |
---|---|
chr() | converts an integer in the range 0 - 10FFFF
to the corresponding length 1 string object |
str.encode() | convert a str to bytes (array), using the given text encoding. UTF-8 is the default endoding chr(0x70).encode() e' lungo 1 byte chr(0x10FFFF).encode() e' lungo 4 byte |
bytes.decode() | achieve the opposite |