Recently I started teaching my son Python. I don't know Python before. So I have to learn it while teaching him. I intended to learn Python for quite some time, but time has always been my biggest enemy, together with my memory: it's getting worse every year. If I learn something and don't use it immediately, then it's quite possible after 3 months, I'm new to it again. So I start blogging it, trying to make my memory last longer.
Python is an elegant language, it's very expressive and has very brief syntax - though this can be a double side sword - to a experienced programmer with long time Java/C#/C++/C experience, it takes some time to be used to it.
Some points about Python I'd like to note down:
- Python started at 1989, and first public appeared at 1991
- CPython is the C implemented version of Python, then standard Python
- Python generally has 2 kinds of primary types: numbers and strings, though array/list and hashtable/dictionary is first class member of the language.
- Python use space indention to indicate sub-scope. The indent does not have to be unified within program, but must be the same for the same scope
- like most script languages, variables do not need to be pre-claimed before being used
- Python can be compiled into byte codes, like Java class files, with extension .pyo or .pyc
- using '''/""", you can have multiple line strings
- raw string starts with a 'r': r"c:\a\path\file"
- unicode string starts with a 'u': u"this is unicode"
- raw_input() will return anything you input as a string, while input() will try to evaluate your input as Python code! For example:
>>> a = 3
>>> b = input()
a+11
>>> b
14 - Python as +=, -=, *=, /=, similar to other languages, but no i++, ++i, i-- or --i. But ++i or --i won't give you any syntax error, since the +/- are treated two time sign prefix!
No comments:
Post a Comment