[Python] Basic commands, functions and Math

# (octothorpe or pound character)
Everything after the # is ignored by python.
print "text"
string in "" will be printed out.
Integer and Float
1/4 = 0 (int)
1.00 / 4 = (float) 
 % (modulus)
75 % 4 = 3 (75 = 18 * 4 + 3)
2 % 4 = 2 
Variable

myName = "Rovingleaves"
myAge = 40
print "my name is %s. I am %d years old" % (myName, myAge)

  • s: String (converts any python object using str()).
  • d: Signed integer decimal.
  • f: Floating point decimal format.
  • x:  Unsigned hexadecimal (lowercase).
  • X: Unsigned hexadecimal (Uppercase).
Escape Sequences

留言

這個網誌中的熱門文章

[Python] raw_input() function

[Golang] for