You Are Here
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!
pydoc -k string pydoc module pydoc -p 9999
python –m pydoc module
pydoc pydoc
print expression1[, expression2,…,expressionN][,]
# Examples:
a = 12.3
print 'The value of', a, 'is in variable a.'
print 'Is that enough?'
print 'The value of', a, 'is in variable a.',
print 'Is that enough?'
# Output:
The value of 12.3 is in variable a.
Is that enough?
The value of 12.3 is in variable a. Is that enough?
integer float string boolean None
x = 10 (integer)
y = 12.34 (float)
z = ‘text data’ (string)
Compound operators (e.g., +=, -=, etc) work the same in Python as other languages.
No ++ postfix/prefix!
** | Exponentiation |
/ | Division |
* | Multiplication |
+ | Addition |
- | Subtraction |
% | Modulus (Remainder) |
// | Floor Division |
Math with integers produces an integer result in Python 2.
7/3 = 2
7//3 = 2
In Python 3, this changes.
Any division in Python 3 yields a float.
7/3 = 2.3333
Only floor division gives 7//3 = 2
x = 12.3
x = x + 1
y = x + 117
z = 12 * x / y
a = “This is a line of text”
b = “ and so is this”
c = a + b # (string concatenation – do not mix strings with numbers)
d = 20 * ‘-’ # (string replication)
x, y = y, x
x = 'Some text {} more text {}'.format(12, 17.426)
# Result: 'Some text 12 more text 17.426'
x = 'Some text {1} more text {0}'.format(12, 17.426)
# Result: 'Some text 17.426 more text 12 '
x = 'Some text {0:5d} more text {1:7.2f}'.format(12, 17.426)
# Result: 'Some text 12 more text 17.43'
# (Note rounding)
See examples in Sample folder - a2Formats.jpg and a3Formats.jpg