Never, never and never give up!!!
- python version 2.7
- interactive interpreter: practice python in command line
- Python Data Type
- Numbers
- Strings: escape characters by default. Use
print
to avoid unreadable escape characters
Useraw
key words and you don’t need to add escape backslash for each escape characters.
multiple line string: use ” ” ” … ” ” ”
concatenate string: use ‘+’
multiple string: use ‘*’
Two or more string listed adjacent are concatenated by default
But that only works for literal strings, not variables or expressions
- characters in a string in Python can be visited by indices, when -1 is used, starting from right
- slicing: str[0:2] #from indices 0 to indices 2(excluded)
- how start is included? str[:2]
- how end is included? str[2:]
- indices out of bound is treated as error, but slices out of bound are treated elegantly
- characters in a string are immutable
- len() returns the length of a string
- str() returns ASCII string
- encode takes one parameter: of the lower-case named encoding name
- compound data types:
- List
indices and slicing are similar; but List elements are not unimmutable
- List