amt

PCAP

amt
Apr 14th, 2022 (edited)
946
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 7.87 KB | None | 0 0
  1. print('Hello, world!') # Hello, world!
  2. print("hello".upper()) # HELLO
  3. print("""hello""".upper()) # HELLO
  4. print("""hello
  5.      """.upper())
  6. # HELLO
  7. #
  8. print(""" Hello
  9.        world ...""".lower())
  10. # hello
  11. #         world ...
  12. print(("this is a very"
  13.       " long string too"
  14.       "for sure ..."
  15.      )) # this is a very long string toofor sure ...
  16. print(str(1/1)) # 1.0
  17. print(type(str(1/1))) # <class 'str'>
  18. print(type(1/1)) # <class 'float'>
  19. print('T'.lower() in 'beTa') # False
  20. print('T'.lower() in 'bEta') # False
  21. print(ord('b')) # 98
  22. print(ord('a')) # 97
  23. print(chr(97)) # a
  24. print(ord('b') + 2) # 100
  25. print(chr(ord('b') + 2)) # d
  26. print(chr(ord('b') + 2) in 'dogs') # True
  27. print('F' in 'False') # True
  28. # print('F' in False) # TypeError: argument of type 'bool' is not iterable
  29.  
  30. import math
  31. print(math) # <module 'math' (built-in)>
  32. print(type(math)) # <class 'module'>
  33. print(dir(math))
  34. """
  35. ['__doc__', '__loader__', '__name__', '__package__', '__spec__', 'acos', 'acosh', 'asin', 'asinh', 'atan', 'atan2', 'atanh', 'ceil', 'comb', 'copysign', 'cos', 'cosh', 'degrees', 'dist', 'e', 'erf', 'erfc', 'exp', 'expm1', 'fabs', 'factorial', 'floor', 'fmod', 'frexp', 'fsum', 'gamma', 'gcd', 'hypot', 'inf', 'isclose', 'isfinite', 'isinf', 'isnan', 'isqrt', 'ldexp', 'lgamma', 'log', 'log10', 'log1p', 'log2', 'modf', 'nan', 'perm', 'pi', 'pow', 'prod', 'radians', 'remainder', 'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'tau', 'trunc']
  36. """
  37. import math
  38. print(math) # <module 'math' (built-in)>
  39. print(type(math)) # <class 'module'>
  40. pi = 3.141592653589793
  41. # print(math.round(pi)) # AttributeError: module 'math' has no attribute 'round'
  42. print(math.ceil(pi)) # 4
  43. print(round(pi, 0)) # 3.0
  44. print(round(pi)) # 3
  45. print(math.trunc(pi)) # 3
  46. print(math.floor(pi)) # 3
  47. print(round(5.76543, -1)) # 10.0
  48. print(round(5.76543, -10)) # 0.0
  49. print(round(576543, -1)) # 576540
  50. print(round(576543, -10)) # 0
  51. print(round(576543, -5)) # 600000
  52.  
  53. from math import sqrt
  54. # print(math) # NameError: name 'math' is not defined
  55. print(sqrt) # <built-in function sqrt>
  56. # print(sqrt()) # TypeError: sqrt() takes exactly one argument (0 given)
  57. print(sqrt(25)) # 5.0
  58. # print(dir(math)) # NameError: name 'math' is not defined
  59.  
  60. import platform
  61. # print(system) # NameError: name 'system' is not defined
  62. print(platform.system) # <function system at 0x7f65bf600280>
  63. print(platform.system()) # Linux
  64. print(platform.processor) # <function processor at 0x7f65bf600550>
  65. print(platform.processor()) #
  66. print(platform.machine) # <function machine at 0x7f65bf6004c0>
  67. print(platform.machine()) # x86_64
  68. print(platform.platform()) # Linux-5.13.0-1023-gcp-x86_64-with-glibc2.27
  69. print(platform.version()) # #28~20.04.1-Ubuntu SMP Wed Mar 30 03:51:07 UTC 2022
  70.  
  71. from platform import system
  72. print(system()) # Linux
  73.  
  74. """
  75. $ pip show pandas
  76. Name: pandas
  77. Version: 1.2.3
  78. Summary: Powerful data structures for data analysis, time series, and statistics
  79. Home-page: https://pandas.pydata.org
  80. Author: None
  81. Author-email: None
  82. License: BSD
  83. Location: /path/to/lib/python3.6/site-packages
  84. Requires: pytz, python-dateutil, numpy
  85. Required-by: shap, seaborn
  86.  
  87.  
  88. python -m pip list
  89. Package Version
  90. ------- -------
  91. docopt  0.6.2
  92. idlex   1.13
  93. jedi    0.9.0
  94.  
  95.  
  96. python3 -m pip search peppercorn
  97. (Search for PyPI packages whose name or summary contains <query>.)
  98. pepperedform    - Helpers for using peppercorn with formprocess.
  99. peppercorn      - A library for converting a token stream into [...]
  100.  
  101. """
  102.  
  103. try:
  104.   print(int('0'))
  105. except NameError:
  106.   print('0')
  107. else:
  108.   print(int('')) # ValueError: invalid literal for int() with base 10: ''
  109.  
  110. try:
  111.   print(int('0')) # 0
  112. except NameError:
  113.   print('30')
  114.  
  115. try:
  116.   print(0/0)
  117. except :
  118.   print(0/1) # 0.0
  119. else:
  120.   print(2/0)
  121.  
  122. import math
  123. try:
  124.   print(math.sqrt(-1))
  125. except :
  126.   print(math.sqrt(1)) # 1.0
  127. else:
  128.   print(math.sqrt(25))
  129.  
  130. try:
  131.   print(float("1e1"))
  132. except (NameError, SystemError):
  133.   print(float("1.1"))
  134. else:
  135.   print(float('1c1')) # ValueError: could not convert string to float: '1c1'
  136.  
  137. print(float("1e1")) # 10.0
  138. print(float("1.1")) # 1.1
  139.  
  140. try:
  141.   print(1//0)
  142. except ArithmeticError:
  143.   print("Zero Handled by arithmetic branch")
  144. except ZeroDivisionError:
  145.   print("Error handled by zero division branch")
  146. except:
  147.   print("Error handled by except branch")
  148.  
  149. print(1//0) # ZeroDivisionError: integer division or modulo by zero
  150.  
  151. print(issubclass(KeyError, Exception)) # True
  152.  
  153. print(issubclass(KeyError, Exception)) # true
  154. print(issubclass(LookupError, Exception)) # true
  155. print(issubclass(SystemExit, Exception)) # False
  156. print(issubclass(KeyboardInterrupt, Exception)) # False
  157. print(issubclass(SystemExit, BaseException)) # True
  158. print(issubclass(KeyboardInterrupt, BaseException)) # True
  159.  
  160. ----
  161. def foo(x):
  162.   assert x
  163.   return 1/x
  164.  
  165. try:
  166.   print(foo(0))
  167. except ZeroDivisionError:
  168.   print("zero")
  169. except AssertionError as e:
  170.   print(e) #
  171. except:
  172.   print(some)
  173.  
  174. ----
  175. def ooh(x):
  176.   assert x, 'message goes here'
  177.   return 1/x
  178.  
  179. try:
  180.   print(ooh([]))
  181. except ZeroDivisionError:
  182.   print("zero")
  183. except AssertionError as e:
  184.   print(e) # message goes here
  185. except:
  186.   print(some)
  187.  
  188. ----
  189. x = 1E2500 ** 1
  190. print(x) # inf
  191.  
  192. x = 1E250 * 2
  193. print(x) # 2e+250
  194.  
  195. x = 1E308 # 1e+308
  196. print(x) # inf
  197.  
  198. x = 1E309
  199. print(x) # inf
  200.  
  201. x = 1E250 ** 2
  202. print(x) # OverflowError: (34, 'Numerical result out of range')
  203.  
  204. # Unicode Transformation Format (UTF)
  205.  
  206. string = """\\
  207. \\"""
  208. print(len(string)) # 3
  209. print(string)
  210. """
  211. \
  212. \
  213. """
  214.  
  215. string2 = '''\\
  216.  
  217.        \\'''
  218. print(len(string2)) # 12
  219. print(string2)
  220. """
  221. \
  222.  
  223.        \
  224. """
  225.  
  226. alphabet = "abcdefghijklmnopqrstuvwxyz"
  227. alphabet.insert(0, "A") # AttributeError: 'str' object has no attribute 'insert'
  228. del alphabet[0] # TypeError: 'str' object doesn't support item deletion
  229. print(alphabet[-30:30:1]) # abcdefghijklmnopqrstuvwxyz
  230. print(alphabet[-30:30:-1]) #
  231. print(alphabet.lstrip()) # abcdefghijklmnopqrstuvwxyz
  232.  
  233. x = "True"
  234. y = 3
  235. print(x == y) # False
  236. print(x != y) # True
  237. print(x < y) # TypeError: '<' not supported between instances of 'str' and 'int'
  238. print(x > y) # TypeError: '>' not supported between instances of 'str' and 'int'
  239.  
  240. for ch in 'aBc123':
  241.   if ch.isupper():
  242.     print(ch.lower(), end='\n' )
  243.   elif ch.islower():
  244.     print(ch.upper(), end='')
  245.   else:
  246.     print(ch, end='')
  247.  
  248. """
  249. Ab
  250. C123
  251. """
  252.  
  253. s1 = "dog cat rat"
  254. s2 = s1.split()
  255. print(s2[-4:1]) # ['dog']
  256. print(s2) # ['dog', 'cat', 'rat']
  257. print(s1.split('a')) # ['dog c', 't r', 't']
  258. print(s2[-3:1]) # ['dog']
  259. print(s2[-3:0]) # []
  260.  
  261. # Slicing Start
  262.  
  263. a[start:stop]  # items start through stop-1
  264. a[start:]      # items start through the rest of the array
  265. a[:stop]       # items from the beginning through stop-1
  266. a[:]           # a copy of the whole array
  267.  
  268. a[start:stop:step] # start through not past stop, by step
  269.  
  270. a[-1]    # last item in the array
  271. a[-2:]   # last two items in the array
  272. a[:-2]   # everything except the last two items
  273.  
  274. a[::-1]    # all items in the array, reversed
  275. a[1::-1]   # the first two items, reversed
  276. a[:-3:-1]  # the last two items, reversed
  277. a[-3::-1]  # everything except the last two items, reversed
  278.  
  279. a = [1,2,3,4,5,6,7,8,9,0]
  280.  
  281. print(a[0:3]) # [1, 2, 3]
  282. print(a[4:]) # [5, 6, 7, 8, 9, 0]
  283. print(a[:5]) # [1, 2, 3, 4, 5]
  284. print(a[:]) # [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
  285.  
  286. print(a[2:6:2]) # [3, 5]
  287.  
  288. print(a[-1]) # 0
  289. print(a[-2:]) # [9, 0]
  290. print(a[:-2]) # [1, 2, 3, 4, 5, 6, 7, 8]
  291.  
  292. print(a[::-1]) # [0, 9, 8, 7, 6, 5, 4, 3, 2, 1]
  293. print(a[1::-1]) # [2, 1]
  294. print(a[:-3:-1]) # [0, 9]
  295. print(a[-3::-1]) # [8, 7, 6, 5, 4, 3, 2, 1]
  296.  
  297. # Slicing End
  298.  
  299. my_list = ['Hello', 'World', '!']
  300. s = '\\'.join(my_list)
  301. print(s)
  302.  
  303. my_list = ['Hello', 'World', '!']
  304. s = '\\'.join(my_list)
  305. print(s) # Hello\World\!
  306.  
  307. my_Tuple = ("John", "Peter", "Vicky")
  308. x = "#".join(my_Tuple)
  309. print(x) # John#Peter#Vicky
  310.  
  311. myDict = {"name": "John", "country": "Norway"}
  312. mySeparator = "TEST"
  313. y = mySeparator.join(myDict)
  314. print(y) # nameTESTcountry
  315.  
  316.  
Add Comment
Please, Sign In to add comment