Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. Python cheatsheet
  2.  
  3. var = 3 #sets a variable to =3
  4.  
  5. bool = True #sets a boolean to true (must be capitalized)
  6.  
  7. float = 1.22 #sets a var but with decimals
  8.  
  9. string = “Hello World”
  10.  
  11. \ fixes characters that break strings, like ‘
  12.  
  13. # makes a comment
  14.  
  15. “”” sets a
  16. multi line comment”””
  17.  
  18. exponents use ** instead of ^ #2**3=2^3
  19.  
  20. string characters get numbered in an index which can be called with STRINGNAME[PLACE] and the place starts from 0
  21.  
  22. len(stringname) returns the length of a string
  23. STRGINGNAME.lower( ) returns the string with caps lowered (does not edit the string)
  24. .upper( ) is anti .lower
  25. str(STRINGNAME) returns the string version of a non-string like a bool or var (turns 2 into “2”)
  26.  
  27. strings can be added just like numbers
  28. print “Adding “ + “Strings”
  29. can’t add a string to a non-string so use str() to make things into strings
  30.  
  31. also to add strings you can use %s and then after the quotes write % (stringname, stringname2)
  32.  
  33. date and time library can be imported with the starting line "from datetime import datetime” and then used with datetime.now (can be printed or set as a string)
  34. year can be called with STRINGNAME.year (if STRINGNAME = datetime.now), same with month/day
  35.  
  36. equals to ==
  37. not equal to !=
  38. less < less or equal <= and the opposite is more ofc
  39.  
  40. and checks if both statements are True
  41. or makes sure at least one statement of them is true
  42. not gives the opposite of the statement
  43.  
  44. if there’s several, not is checked first, then and, then or
  45. parentheses can be used to ensure the order you want is done tho
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement