Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
python [2019/03/31 21:01]
127.0.0.1 external edit
python [2019/07/09 17:29] (current)
paul [Formatting]
Line 169: Line 169:
   * ''%%strip()%%''   * ''%%strip()%%''
   * ''%%split()%%''   * ''%%split()%%''
 +
 +==== Formatting ====
 +
 +If you want to print a neat line of data use the [[https://docs.python.org/2/library/string.html#format-string-syntax|Format String Syntax]].
 +
 +For example: 
 +<code python>
 +print("[ FAIL ] {: <20} Channel: {: <20} Statistics: {:>6.4f} hz".format(description, chan, stats))
 +</code>
 +
 +This sets a fix width for each field and aligns the test either left ''%%<%%'' or right ''%%>%%''
  
 ===== Mutability ===== ===== Mutability =====
Line 266: Line 277:
 You can assign lists uisng text parallel assignment You can assign lists uisng text parallel assignment
 <code python> <code python>
-firstname, lastname = ["Dildo", "Baggins"]+firstname, lastname = ["Bilbo", "Baggins"]
 </code> </code>
  
-God python is so wierd with shit, like, theres all these nice little features+God python is so wierd with shit, like, there'all these nice little features
 everywhere. Haha. everywhere. Haha.
  
Line 305: Line 316:
 t = (1,2,3) t = (1,2,3)
 l = list(t) l = list(t)
-l.append("dicks")+l.append("apples")
 t = tuple(l) t = tuple(l)
 </code> </code>
  • python.1554066070.txt.gz
  • Last modified: 2019/03/31 21:01
  • by 127.0.0.1