Difference between revisions of "Python"

From LPTMS Wiki
Jump to: navigation, search
m (Tips)
m (Tips)
Line 28: Line 28:
 
== Tips ==
 
== Tips ==
  
* equivalent of the C ternary operator bool?restrue:resfalse
+
* equivalent of the C ternary operator ?: (''bool'' ? ''restrue'' : ''resfalse''), use a tuple
 
<source lang="py">
 
<source lang="py">
 
(resfalse,restrue)[bool]
 
(resfalse,restrue)[bool]

Revision as of 17:19, 23 November 2011

documentation

Libraries

Miscellaneous

Tips

  • equivalent of the C ternary operator ?: (bool ? restrue : resfalse), use a tuple

(resfalse,restrue)[bool]
  • adding a path to a directory containing your module files

import sys
sys.path += [ "/home/username/bin/Python" ]
  • test whether a string has only digits or letters

str = '1321'
str.isdigit() # returns True/False
str.isalpha() # returns True/False