Advertisement
teslariu

colecciones y mas

Jun 27th, 2023
1,132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 9.42 KB | None | 0 0
  1. >>> lista = []
  2. >>> lista = [1,"we", True, [1,2,3], 78]
  3. >>> lista[0]
  4. 1
  5. >>> lista[1]
  6. 'we'
  7. >>> lista[-1]
  8. 78
  9. >>> lista[-2]
  10. [1, 2, 3]
  11. >>>
  12. >>> lista[-1] = "Soy el ultimo"
  13. >>> lista
  14. [1, 'we', True, [1, 2, 3], 'Soy el ultimo']
  15. >>> lista.append(25)
  16. >>> lista
  17. [1, 'we', True, [1, 2, 3], 'Soy el ultimo', 25]
  18. >>> lista.insert(1,"Segundo")
  19. >>> lista
  20. [1, 'Segundo', 'we', True, [1, 2, 3], 'Soy el ultimo', 25]
  21. >>> del(lista[2])
  22. >>> lista
  23. [1, 'Segundo', True, [1, 2, 3], 'Soy el ultimo', 25]
  24. >>> 23.append(12)
  25.   File "<stdin>", line 1
  26.     23.append(12)
  27.       ^
  28. SyntaxError: invalid decimal literal
  29. >>> a = 23
  30. >>> a.append(12)
  31. Traceback (most recent call last):
  32.   File "<stdin>", line 1, in <module>
  33. AttributeError: 'int' object has no attribute 'append'
  34. >>> lista[3]
  35. [1, 2, 3]
  36. >>> lista[3][1]
  37. 2
  38. >>> lista
  39. [1, 'Segundo', True, [1, 2, 3], 'Soy el ultimo', 25]
  40. >>> del(lista[3][1])
  41. >>> lista
  42. [1, 'Segundo', True, [1, 3], 'Soy el ultimo', 25]
  43. >>> help(list)
  44. Help on class list in module builtins:
  45.  
  46. class list(object)
  47.  |  list(iterable=(), /)
  48.  |
  49.  |  Built-in mutable sequence.
  50.  |
  51.  |  If no argument is given, the constructor creates a new empty list.
  52.  |  The argument must be an iterable if specified.
  53.  |
  54.  |  Methods defined here:
  55.  |
  56.  |  __add__(self, value, /)
  57.  |      Return self+value.
  58.  |
  59.  |  __contains__(self, key, /)
  60.  |      Return key in self.
  61.  |
  62.  |  __delitem__(self, key, /)
  63.  |      Delete self[key].
  64.  |
  65.  |  __eq__(self, value, /)
  66.  |      Return self==value.
  67.  |
  68.  |  __ge__(self, value, /)
  69.  |      Return self>=value.
  70.  |
  71.  |  __getattribute__(self, name, /)
  72.  |      Return getattr(self, name).
  73.  |
  74.  |  __getitem__(...)
  75.  |      x.__getitem__(y) <==> x[y]
  76.  |
  77.  |  __gt__(self, value, /)
  78.  |      Return self>value.
  79.  |
  80.  |  __iadd__(self, value, /)
  81.  |      Implement self+=value.
  82.  |
  83.  |  __imul__(self, value, /)
  84.  |      Implement self*=value.
  85.  |
  86.  |  __init__(self, /, *args, **kwargs)
  87.  |      Initialize self.  See help(type(self)) for accurate signature.
  88.  |
  89.  |  __iter__(self, /)
  90.  |      Implement iter(self).
  91.  |
  92.  |  __le__(self, value, /)
  93.  |      Return self<=value.
  94.  |
  95.  |  __len__(self, /)
  96.  |      Return len(self).
  97.  |
  98.  |  __lt__(self, value, /)
  99.  |      Return self<value.
  100.  |
  101.  |  __mul__(self, value, /)
  102.  |      Return self*value.
  103.  |
  104.  |  __ne__(self, value, /)
  105.  |      Return self!=value.
  106.  |
  107.  |  __repr__(self, /)
  108.  |      Return repr(self).
  109.  |
  110.  |  __reversed__(self, /)
  111.  |      Return a reverse iterator over the list.
  112.  |
  113.  |  __rmul__(self, value, /)
  114.  |      Return value*self.
  115.  |
  116.  |  __setitem__(self, key, value, /)
  117.  |      Set self[key] to value.
  118.  |
  119.  |  __sizeof__(self, /)
  120.  |      Return the size of the list in memory, in bytes.
  121.  |
  122.  |  append(self, object, /)
  123.  |      Append object to the end of the list.
  124.  |
  125.  |  clear(self, /)
  126.  |      Remove all items from list.
  127.  |
  128.  |  copy(self, /)
  129.  |      Return a shallow copy of the list.
  130.  |
  131.  |  count(self, value, /)
  132.  |      Return number of occurrences of value.
  133.  |
  134.  |  extend(self, iterable, /)
  135.  |      Extend list by appending elements from the iterable.
  136.  |
  137.  |  index(self, value, start=0, stop=9223372036854775807, /)
  138.  |      Return first index of value.
  139.  |
  140.  |      Raises ValueError if the value is not present.
  141.  |
  142.  |  insert(self, index, object, /)
  143.  |      Insert object before index.
  144.  |
  145.  |  pop(self, index=-1, /)
  146.  |      Remove and return item at index (default last).
  147.  
  148. >>> lista
  149. [1, 'Segundo', True, [1, 3], 'Soy el ultimo', 25]
  150. >>> lista.clear()
  151. >>> lista
  152. []
  153. >>> tupla = (1,2,3)
  154. >>> tupla(-1)
  155. Traceback (most recent call last):
  156.   File "<stdin>", line 1, in <module>
  157. TypeError: 'tuple' object is not callable
  158. >>> tupla[-1]
  159. 3
  160. >>> tupla[-1] = 45
  161. Traceback (most recent call last):
  162.   File "<stdin>", line 1, in <module>
  163. TypeError: 'tuple' object does not support item assignment
  164. >>> del(tupla[0])
  165. Traceback (most recent call last):
  166.   File "<stdin>", line 1, in <module>
  167. TypeError: 'tuple' object doesn't support item deletion
  168. >>> tupla = (1)
  169. >>> type(tupla)
  170. <class 'int'>
  171. >>> tupla = (1,)
  172. >>> type(tupla)
  173. <class 'tuple'>
  174. >>> help(tuple)
  175. Help on class tuple in module builtins:
  176.  
  177. class tuple(object)
  178. |  tuple(iterable=(), /)
  179. |
  180. |  Built-in immutable sequence.
  181. |
  182. |  If no argument is given, the constructor returns an empty tuple.
  183. |  If iterable is specified the tuple is initialized from iterable's items.
  184.  |
  185.  |  If the argument is a tuple, the return value is the same object.
  186.  |
  187.  |  Built-in subclasses:
  188.  |      asyncgen_hooks
  189.  |      UnraisableHookArgs
  190.  |
  191.  |  Methods defined here:
  192.  |
  193.  |  __add__(self, value, /)
  194.  |      Return self+value.
  195.  |
  196.  |  __contains__(self, key, /)
  197.  |      Return key in self.
  198.  |
  199.  |  __eq__(self, value, /)
  200.  |      Return self==value.
  201.  |
  202.  |  __ge__(self, value, /)
  203.  |      Return self>=value.
  204.  |
  205.  |  __getattribute__(self, name, /)
  206.  |      Return getattr(self, name).
  207.  |
  208.  |  __getitem__(self, key, /)
  209.  |      Return self[key].
  210.  |
  211.  |  __getnewargs__(self, /)
  212.  |
  213.  |  __gt__(self, value, /)
  214.  |      Return self>value.
  215.  |
  216.  |  __hash__(self, /)
  217.  |      Return hash(self).
  218.  |
  219.  |  __iter__(self, /)
  220.  |      Implement iter(self).
  221.  |
  222.  |  __le__(self, value, /)
  223.  |      Return self<=value.
  224.  |
  225.  |  __len__(self, /)
  226.  |      Return len(self).
  227.  |
  228.  |  __lt__(self, value, /)
  229.  |      Return self<value.
  230.  |
  231.  |  __mul__(self, value, /)
  232.  |      Return self*value.
  233.  |
  234.  |  __ne__(self, value, /)
  235.  |      Return self!=value.
  236.  |
  237.  |  __repr__(self, /)
  238.  |      Return repr(self).
  239.  |
  240.  |  __rmul__(self, value, /)
  241.  |      Return value*self.
  242.  |
  243.  |  count(self, value, /)
  244.  |      Return number of occurrences of value.
  245.  |
  246.  |  index(self, value, start=0, stop=9223372036854775807, /)
  247.  |      Return first index of value.
  248.  |
  249.  |      Raises ValueError if the value is not present.
  250.  |
  251.  |  ----------------------------------------------------------------------
  252.  |  Class methods defined here:
  253.  |
  254.  |  __class_getitem__(...) from builtins.type
  255.  |      See PEP 585
  256.  |
  257.  |  ----------------------------------------------------------------------
  258.  |  Static methods defined here:
  259.  |
  260.  |  __new__(*args, **kwargs) from builtins.type
  261.  |      Create and return a new object.  See help(type) for accurate signature.
  262.  
  263. >>>
  264. >>>
  265. >>>
  266. >>>
  267. >>>
  268. >>>
  269. >>>
  270. >>>
  271. >>>
  272. >>>
  273. >>> dicc = {}
  274. >>> type(dicc)
  275. <class 'dict'>
  276. >>> dicc = {"marron":"brown", "rojo":"red", "gris":"gray"}
  277. >>> len(dicc)
  278. 3
  279. >>> lista
  280. []
  281. >>> lista = [1,"we", True, [1,2,3], 78]
  282. >>> len(lista)
  283. 5
  284. >>> lista = [12,253,-256,0.002,-0.25]
  285. >>> max(lista)
  286. 253
  287. >>> min(lista)
  288. -256
  289. >>> sum(lista)
  290. 8.752
  291. >>> sum(lista)/len(lista)
  292. 1.7504000000000002
  293. >>> f"{sum(lista)/len(lista):-2f}"
  294. '1.750400'
  295. >>> f"{sum(lista)/len(lista):.2f}"
  296. '1.75'
  297. >>> f"{sum(lista)/len(lista):.4f}"
  298. '1.7504'
  299. >>> lista.sort()
  300. >>> lista
  301. [-256, -0.25, 0.002, 12, 253]
  302. >>> lista.sort(reversed=False)
  303. Traceback (most recent call last):
  304.   File "<stdin>", line 1, in <module>
  305. TypeError: 'reversed' is an invalid keyword argument for sort()
  306. >>> lista.sort(reverse=False)
  307. >>> lista
  308. [-256, -0.25, 0.002, 12, 253]
  309. >>> lista.sort(reverse=True)
  310. >>> lista
  311. [253, 12, 0.002, -0.25, -256]
  312. >>> dicc
  313. {'marron': 'brown', 'rojo': 'red', 'gris': 'gray'}
  314. >>> dicc["blanco"] = "white"
  315. >>> dicc
  316. {'marron': 'brown', 'rojo': 'red', 'gris': 'gray', 'blanco': 'white'}
  317. >>> dicc["marron"]
  318. 'brown'
  319. >>> agenda = {"ale":3132135, "ale":456465}
  320. >>> agenda
  321. {'ale': 456465}
  322. >>> agenda = {"ale":[3132135,456465]}
  323. >>> agenda
  324. {'ale': [3132135, 456465]}
  325. >>> agenda = {31326+65:"ale"; 9987789879:"ale"}
  326.   File "<stdin>", line 1
  327.     agenda = {31326+65:"ale"; 9987789879:"ale"}
  328.                             ^
  329. SyntaxError: invalid syntax
  330. >>> agenda = {31326+65:"ale", 9987789879:"ale"}
  331. >>> agenda
  332. {31391: 'ale', 9987789879: 'ale'}
  333. >>> agenda.clear()
  334. >>> agenda
  335. {}
  336. >>> dicc
  337. {'marron': 'brown', 'rojo': 'red', 'gris': 'gray', 'blanco': 'white'}
  338. >>> dicc["colorado"] = "red"
  339. >>> dicc
  340. {'marron': 'brown', 'rojo': 'red', 'gris': 'gray', 'blanco': 'white', 'colorado': 'red'}
  341. >>> dicc["gris"] = "grey"
  342. >>> dicc
  343. {'marron': 'brown', 'rojo': 'red', 'gris': 'grey', 'blanco': 'white', 'colorado': 'red'}
  344. >>> dicc.values()
  345. dict_values(['brown', 'red', 'grey', 'white', 'red'])
  346. >>> list(dicc.values())
  347. ['brown', 'red', 'grey', 'white', 'red']
  348. >>> list(dicc.keys())
  349. ['marron', 'rojo', 'gris', 'blanco', 'colorado']
  350. >>> for k,v in dicc.items():
  351. ...     print(k,v)
  352. ...
  353. marron brown
  354. rojo red
  355. gris grey
  356. blanco white
  357. colorado red
  358. >>> frase = "soy una frase"
  359. >>> len(frase)
  360. 13
  361. >>> frase.endswith("se")
  362. True
  363. >>> frase.endswith("ce")
  364. False
  365. >>> frase.startswith("ce")
  366. False
  367. >>> frase.upper()
  368. 'SOY UNA FRASE'
  369. >>> frase.swapcase()
  370. 'SOY UNA FRASE'
  371. >>> frase.lower()
  372. 'soy una frase'
  373. >>> frase = "jkjKOKKKKñññ"
  374. >>> frase.swapcase()
  375. 'JKJkokkkkÑÑÑ'
  376. >>> frase
  377. 'jkjKOKKKKñññ'
  378. >>> frase.lower()
  379. 'jkjkokkkkñññ'
  380. >>> frase
  381. 'jkjKOKKKKñññ'
  382. >>> frase = "HOLA a todos"
  383. >>> frase.lower()
  384. 'hola a todos'
  385. >>> frase.upper()
  386. 'HOLA A TODOS'
  387. >>> frase.swapcase()
  388. 'hola A TODOS'
  389. >>> frase
  390. 'HOLA a todos'
  391. >>> frase = frase.swapcase()
  392. >>> frase
  393. 'hola A TODOS'
  394. >>> frase[-1]
  395. 'S'
  396. >>> frase[0]
  397. 'h'
  398. >>> lista
  399. [253, 12, 0.002, -0.25, -256]
  400. >>> lista[1:]
  401. [12, 0.002, -0.25, -256]
  402. >>> lista[1:-1]
  403. [12, 0.002, -0.25]
  404. >>> lista[1:-1:2]
  405. [12, -0.25]
  406. >>> frase
  407. 'hola A TODOS'
  408. >>> frase[:]
  409. 'hola A TODOS'
  410. >>> frase[:-1]
  411. 'hola A TODO'
  412. >>> frase[2:-2]
  413. 'la A TOD'
  414. >>> lista
  415. [253, 12, 0.002, -0.25, -256]
  416. >>> a,b,c,d,e=lista
  417. >>> a
  418. 253
  419. >>> b
  420. 12
  421. >>> c
  422. 0.002
  423. >>> d
  424. -0.25
  425. >>> e
  426. -256
  427. >>>
  428.  
  429.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement