Advertisement
yiwen_akeni

python cheatsheet

Aug 4th, 2024 (edited)
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.15 KB | Source Code | 0 0
  1. every instruction in one line, can't more
  2. print("texte")
  3. print("texte\ntext in new line")
  4. print("text0","text1") => text0 text1 (put auto space)
  5. print("\") invocat an error, correct print("\\")
  6. #print without pass to new line
  7.      print("text" end=" ")
  8.      print("second text")
  9. print("My", "name", "is", "Monty", "Python.", sep="-") # ->out put separat strigs with '-'
  10. print("text "*2) #output -> text text
  11. ‐--------------------------
  12. 55_555_555 = 55555555
  13. 9. =9.0
  14. .6 = 0.6
  15. 3e8 = 3E8 = 3 x 10**8
  16. --------------------
  17. //  integer division or floor division
  18. %   Remainder (modulo)
  19. ** Exponentiation
  20. ‐-----------------------
  21. Don't use as a variable:
  22. ['False', 'None', 'True', 'and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda', 'nonlocal', 'not', 'or', 'pass', 'raise', 'return', 'try', 'while', 'with', 'yield']
  23. ‐---------‐--‐-------------
  24. Text Type:  str
  25. Numeric Types:  int, float, complex
  26. Sequence Types:     list, tuple, range
  27. Mapping Type:   dict
  28. Set Types:  set, frozenset
  29. Boolean Type:   bool
  30. Binary Types:   bytes, bytearray, memoryview
  31. None Type:  NoneType
  32. ------------------
  33. capitalize()    Converts the first character to upper case
  34. casefold()  Converts string into lower case
  35. center()    Returns a centered string
  36. count()         Returns the number of times a specified value occurs in a string
  37. encode()    Returns an encoded version of the string
  38. endswith()  Returns true if the string ends with the specified value
  39. expandtabs()    Sets the tab size of the string
  40. find()          Searches the string for a specified value and returns the position of where it was found
  41. format()    Formats specified values in a string
  42. format_map()    Formats specified values in a string
  43. index() Searches the string for a specified value and returns the position of where it was found
  44. isalnum()   Returns True if all characters in the string are alphanumeric
  45. isalpha()   Returns True if all characters in the string are in the alphabet
  46. isdecimal() Returns True if all characters in the string are decimals
  47. isdigit()   Returns True if all characters in the string are digits
  48. isidentifier()  Returns True if the string is an identifier
  49. islower()   Returns True if all characters in the string are lower case
  50. isnumeric() Returns True if all characters in the string are numeric
  51. isprintable()   Returns True if all characters in the string are printable
  52. isspace()   Returns True if all characters in the string are whitespaces
  53. istitle()   Returns True if the string follows the rules of a title
  54. isupper()   Returns True if all characters in the string are upper case
  55. join()  Joins the elements of an iterable to the end of the string
  56. ljust() Returns a left justified version of the string
  57. lower() Converts a string into lower case
  58. lstrip()    Returns a left trim version of the string
  59. maketrans() Returns a translation table to be used in translations
  60. partition() Returns a tuple where the string is parted into three parts
  61. replace()   Returns a string where a specified value is replaced with a specified value
  62. rfind() Searches the string for a specified value and returns the last position of where it was found
  63. rindex()    Searches the string for a specified value and returns the last position of where it was found
  64. rjust() Returns a right justified version of the string
  65. rpartition()    Returns a tuple where the string is parted into three parts
  66. rsplit()    Splits the string at the specified separator, and returns a list
  67. rstrip()    Returns a right trim version of the string
  68. split() Splits the string at the specified separator, and returns a list
  69. splitlines()    Splits the string at line breaks and returns a list
  70. startswith()    Returns true if the string starts with the specified value
  71. strip() Returns a trimmed version of the string
  72. swapcase()  Swaps cases, lower case becomes upper case and vice versa
  73. title() Converts the first character of each word to upper case
  74. translate() Returns a translated string
  75. upper() Converts a string into upper case
  76. zfill() Fills the string with a specified number of 0 values at the beginning
  77. max(x,y,z,a,...)  return the biggiest number.
  78. min()  retun the lowest number
  79.  
  80.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement