Wednesday, April 20, 2016

python note

Java is a statically typed language, i.e. the types are checked and enforced at compile time. In contrast, Python is dynamic which means that the types are checked only at runtime.
Python also supports a rich set of functional programming features and idioms. In Python, functions are first-class objects that can be created, manipulated and passed around just
like any other object.

== is for value equality.
is is for reference equality.

The // operator is also provided for doing floor division no matter what the operands are.
>>> 17 / 3.0  # int / float -> float
5.666666666666667
>>> 17 // 3.0  # explicit floor division discards the fractional part
5.0

Python is an interpreted language, which can save you considerable time during program development because no compilation and linking is necessary.
The interpreter can be used interactively.

ensures they are always cleaned up promptly and correctly.
with open("myfile.txt") as f:
    for line in f:
        print line

comments:
# or """ """


write file:
>>> out=open("data.out","w")
>>> print("Its a write test for Python",file=out)
>>> out.close

try/except/finally
try:
data = open('its.txt', "w")
print("It's...", file=data)
except IOError as err:
print('File error: ' + str(err))
finally:
if 'data' in locals():
data.close()

No comments:

Post a Comment