Python is just the language for you.
Unicode Strings
Programs written in Python are typically much shorter than equivalent C, C++, or Java programs, for several reasons:
- the high-level data types allow you to express complex operations in a single statement;
- statement grouping is done by indentation instead of beginning and ending brackets;
- no variable or argument declarations are necessary.The language is named after the BBC show “Monty Python’s Flying Circus” and has nothing to do with reptiles.
Numbers
Python also has built-in support for complex numbers, and uses the j or J suffix to indicate the imaginary part (e.g. 3+5j).
String
Strings can be concatenated (glued together) with the + operator, and repeated with *
Two or more string literals (i.e. the ones enclosed between quotes) next to each other are automatically concatenated.
Strings can be indexed (subscripted), with the first character having index 0. There is no separate character type; a character is simply a string of size one:
Indices may also be negative numbers, to start counting from the right:
slicing is also supported. While indexing is used to obtain individual characters, slicing allows you to obtain a substring:
an omitted first index defaults to zero, an omitted second index defaults to the size of the string being sliced.
Python strings cannot be changed — they are immutable. Therefore, assigning to an indexed position in the string results in an error:
Unicode Strings
Creating Unicode strings in Python is just as simple as creating normal strings:
The built-in function unicode() provides access to all registered Unicode codecs (COders and DECoders)
When a Unicode string is printed, written to a file, or converted with str(), conversion takes place using this default encoding.
To convert a Unicode string into an 8-bit string using a specific encoding, Unicode objects provide an encode() method that takes one argument, the name of the encoding. Lowercase names for encodings are preferred.
Lists
list, which can be written as a list of comma-separated values (items) between square brackets
Unlike strings, which are immutable, lists are a mutable type
You can also add new items at the end of the list, by using the append() method
It is possible to nest lists (create lists containing other lists), for example:
Reference : https://docs.python.org/2/tutorial/
When a Unicode string is printed, written to a file, or converted with str(), conversion takes place using this default encoding.
To convert a Unicode string into an 8-bit string using a specific encoding, Unicode objects provide an encode() method that takes one argument, the name of the encoding. Lowercase names for encodings are preferred.
Lists
list, which can be written as a list of comma-separated values (items) between square brackets
Unlike strings, which are immutable, lists are a mutable type
You can also add new items at the end of the list, by using the append() method
It is possible to nest lists (create lists containing other lists), for example:
Reference : https://docs.python.org/2/tutorial/
No comments :
Post a Comment