orashi
cippus_sss
CIPPUS_Python 1st week
Yuanzheng Ci, Screw Studio @ DUT,
2017-11-5
The Zen of Python, by Tim Peters
Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!
Here is the plan: when someone uses a feature you don't understand, simply shoot them.
This is easier than learning something new, and too long the only living coders will be writing in an easily understood, tiny subset of Python 0.9.6
---Tim Peters
Interpreter
IDE
Shell
Distribution
pip
Literals
Identifiers
Operators&Delimiters
Expression
Statement
A statement is executed by the interpreter to perform an action
What is the value of the final expression in this sequence?
Arrows indicate evaluation order
Each name is bound to a value
Within a frame, a name cannot be repeated
3
To look up some name in the body of the square function
Every expression is evaluated in the context of an environment.
Most important two things
Def statement:
A new function is created!
Name bound to that function
in the current frame
Call expression:
Operator & operands evaluated
Function(value of operator) called on arguements
Calling/Applying:
A new frame is created!
Parameters bound to arguments
Body is executed in that new environment
and...
square = lambda x: x * x
def square(x):
return x * x
Both create a function with the same behavior.
Both functions have as their parent the frame in which they were defined
Both bind that function to the name square
Only the def statement gives the function an intrinsic name
False values in Python:
True values in Python:
False, 0, '', None, ......
Anything else (True)
A range is a sequence of consecutive integers
By orashi
cippus first week python meetup