Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- >>> lista = []
- >>> lista = [1,"we", True, [1,2,3], 78]
- >>> lista[0]
- 1
- >>> lista[1]
- 'we'
- >>> lista[-1]
- 78
- >>> lista[-2]
- [1, 2, 3]
- >>>
- >>> lista[-1] = "Soy el ultimo"
- >>> lista
- [1, 'we', True, [1, 2, 3], 'Soy el ultimo']
- >>> lista.append(25)
- >>> lista
- [1, 'we', True, [1, 2, 3], 'Soy el ultimo', 25]
- >>> lista.insert(1,"Segundo")
- >>> lista
- [1, 'Segundo', 'we', True, [1, 2, 3], 'Soy el ultimo', 25]
- >>> del(lista[2])
- >>> lista
- [1, 'Segundo', True, [1, 2, 3], 'Soy el ultimo', 25]
- >>> 23.append(12)
- File "<stdin>", line 1
- 23.append(12)
- ^
- SyntaxError: invalid decimal literal
- >>> a = 23
- >>> a.append(12)
- Traceback (most recent call last):
- File "<stdin>", line 1, in <module>
- AttributeError: 'int' object has no attribute 'append'
- >>> lista[3]
- [1, 2, 3]
- >>> lista[3][1]
- 2
- >>> lista
- [1, 'Segundo', True, [1, 2, 3], 'Soy el ultimo', 25]
- >>> del(lista[3][1])
- >>> lista
- [1, 'Segundo', True, [1, 3], 'Soy el ultimo', 25]
- >>> help(list)
- Help on class list in module builtins:
- class list(object)
- | list(iterable=(), /)
- |
- | Built-in mutable sequence.
- |
- | If no argument is given, the constructor creates a new empty list.
- | The argument must be an iterable if specified.
- |
- | Methods defined here:
- |
- | __add__(self, value, /)
- | Return self+value.
- |
- | __contains__(self, key, /)
- | Return key in self.
- |
- | __delitem__(self, key, /)
- | Delete self[key].
- |
- | __eq__(self, value, /)
- | Return self==value.
- |
- | __ge__(self, value, /)
- | Return self>=value.
- |
- | __getattribute__(self, name, /)
- | Return getattr(self, name).
- |
- | __getitem__(...)
- | x.__getitem__(y) <==> x[y]
- |
- | __gt__(self, value, /)
- | Return self>value.
- |
- | __iadd__(self, value, /)
- | Implement self+=value.
- |
- | __imul__(self, value, /)
- | Implement self*=value.
- |
- | __init__(self, /, *args, **kwargs)
- | Initialize self. See help(type(self)) for accurate signature.
- |
- | __iter__(self, /)
- | Implement iter(self).
- |
- | __le__(self, value, /)
- | Return self<=value.
- |
- | __len__(self, /)
- | Return len(self).
- |
- | __lt__(self, value, /)
- | Return self<value.
- |
- | __mul__(self, value, /)
- | Return self*value.
- |
- | __ne__(self, value, /)
- | Return self!=value.
- |
- | __repr__(self, /)
- | Return repr(self).
- |
- | __reversed__(self, /)
- | Return a reverse iterator over the list.
- |
- | __rmul__(self, value, /)
- | Return value*self.
- |
- | __setitem__(self, key, value, /)
- | Set self[key] to value.
- |
- | __sizeof__(self, /)
- | Return the size of the list in memory, in bytes.
- |
- | append(self, object, /)
- | Append object to the end of the list.
- |
- | clear(self, /)
- | Remove all items from list.
- |
- | copy(self, /)
- | Return a shallow copy of the list.
- |
- | count(self, value, /)
- | Return number of occurrences of value.
- |
- | extend(self, iterable, /)
- | Extend list by appending elements from the iterable.
- |
- | index(self, value, start=0, stop=9223372036854775807, /)
- | Return first index of value.
- |
- | Raises ValueError if the value is not present.
- |
- | insert(self, index, object, /)
- | Insert object before index.
- |
- | pop(self, index=-1, /)
- | Remove and return item at index (default last).
- >>> lista
- [1, 'Segundo', True, [1, 3], 'Soy el ultimo', 25]
- >>> lista.clear()
- >>> lista
- []
- >>> tupla = (1,2,3)
- >>> tupla(-1)
- Traceback (most recent call last):
- File "<stdin>", line 1, in <module>
- TypeError: 'tuple' object is not callable
- >>> tupla[-1]
- 3
- >>> tupla[-1] = 45
- Traceback (most recent call last):
- File "<stdin>", line 1, in <module>
- TypeError: 'tuple' object does not support item assignment
- >>> del(tupla[0])
- Traceback (most recent call last):
- File "<stdin>", line 1, in <module>
- TypeError: 'tuple' object doesn't support item deletion
- >>> tupla = (1)
- >>> type(tupla)
- <class 'int'>
- >>> tupla = (1,)
- >>> type(tupla)
- <class 'tuple'>
- >>> help(tuple)
- Help on class tuple in module builtins:
- class tuple(object)
- | tuple(iterable=(), /)
- |
- | Built-in immutable sequence.
- |
- | If no argument is given, the constructor returns an empty tuple.
- | If iterable is specified the tuple is initialized from iterable's items.
- |
- | If the argument is a tuple, the return value is the same object.
- |
- | Built-in subclasses:
- | asyncgen_hooks
- | UnraisableHookArgs
- |
- | Methods defined here:
- |
- | __add__(self, value, /)
- | Return self+value.
- |
- | __contains__(self, key, /)
- | Return key in self.
- |
- | __eq__(self, value, /)
- | Return self==value.
- |
- | __ge__(self, value, /)
- | Return self>=value.
- |
- | __getattribute__(self, name, /)
- | Return getattr(self, name).
- |
- | __getitem__(self, key, /)
- | Return self[key].
- |
- | __getnewargs__(self, /)
- |
- | __gt__(self, value, /)
- | Return self>value.
- |
- | __hash__(self, /)
- | Return hash(self).
- |
- | __iter__(self, /)
- | Implement iter(self).
- |
- | __le__(self, value, /)
- | Return self<=value.
- |
- | __len__(self, /)
- | Return len(self).
- |
- | __lt__(self, value, /)
- | Return self<value.
- |
- | __mul__(self, value, /)
- | Return self*value.
- |
- | __ne__(self, value, /)
- | Return self!=value.
- |
- | __repr__(self, /)
- | Return repr(self).
- |
- | __rmul__(self, value, /)
- | Return value*self.
- |
- | count(self, value, /)
- | Return number of occurrences of value.
- |
- | index(self, value, start=0, stop=9223372036854775807, /)
- | Return first index of value.
- |
- | Raises ValueError if the value is not present.
- |
- | ----------------------------------------------------------------------
- | Class methods defined here:
- |
- | __class_getitem__(...) from builtins.type
- | See PEP 585
- |
- | ----------------------------------------------------------------------
- | Static methods defined here:
- |
- | __new__(*args, **kwargs) from builtins.type
- | Create and return a new object. See help(type) for accurate signature.
- >>>
- >>>
- >>>
- >>>
- >>>
- >>>
- >>>
- >>>
- >>>
- >>>
- >>> dicc = {}
- >>> type(dicc)
- <class 'dict'>
- >>> dicc = {"marron":"brown", "rojo":"red", "gris":"gray"}
- >>> len(dicc)
- 3
- >>> lista
- []
- >>> lista = [1,"we", True, [1,2,3], 78]
- >>> len(lista)
- 5
- >>> lista = [12,253,-256,0.002,-0.25]
- >>> max(lista)
- 253
- >>> min(lista)
- -256
- >>> sum(lista)
- 8.752
- >>> sum(lista)/len(lista)
- 1.7504000000000002
- >>> f"{sum(lista)/len(lista):-2f}"
- '1.750400'
- >>> f"{sum(lista)/len(lista):.2f}"
- '1.75'
- >>> f"{sum(lista)/len(lista):.4f}"
- '1.7504'
- >>> lista.sort()
- >>> lista
- [-256, -0.25, 0.002, 12, 253]
- >>> lista.sort(reversed=False)
- Traceback (most recent call last):
- File "<stdin>", line 1, in <module>
- TypeError: 'reversed' is an invalid keyword argument for sort()
- >>> lista.sort(reverse=False)
- >>> lista
- [-256, -0.25, 0.002, 12, 253]
- >>> lista.sort(reverse=True)
- >>> lista
- [253, 12, 0.002, -0.25, -256]
- >>> dicc
- {'marron': 'brown', 'rojo': 'red', 'gris': 'gray'}
- >>> dicc["blanco"] = "white"
- >>> dicc
- {'marron': 'brown', 'rojo': 'red', 'gris': 'gray', 'blanco': 'white'}
- >>> dicc["marron"]
- 'brown'
- >>> agenda = {"ale":3132135, "ale":456465}
- >>> agenda
- {'ale': 456465}
- >>> agenda = {"ale":[3132135,456465]}
- >>> agenda
- {'ale': [3132135, 456465]}
- >>> agenda = {31326+65:"ale"; 9987789879:"ale"}
- File "<stdin>", line 1
- agenda = {31326+65:"ale"; 9987789879:"ale"}
- ^
- SyntaxError: invalid syntax
- >>> agenda = {31326+65:"ale", 9987789879:"ale"}
- >>> agenda
- {31391: 'ale', 9987789879: 'ale'}
- >>> agenda.clear()
- >>> agenda
- {}
- >>> dicc
- {'marron': 'brown', 'rojo': 'red', 'gris': 'gray', 'blanco': 'white'}
- >>> dicc["colorado"] = "red"
- >>> dicc
- {'marron': 'brown', 'rojo': 'red', 'gris': 'gray', 'blanco': 'white', 'colorado': 'red'}
- >>> dicc["gris"] = "grey"
- >>> dicc
- {'marron': 'brown', 'rojo': 'red', 'gris': 'grey', 'blanco': 'white', 'colorado': 'red'}
- >>> dicc.values()
- dict_values(['brown', 'red', 'grey', 'white', 'red'])
- >>> list(dicc.values())
- ['brown', 'red', 'grey', 'white', 'red']
- >>> list(dicc.keys())
- ['marron', 'rojo', 'gris', 'blanco', 'colorado']
- >>> for k,v in dicc.items():
- ... print(k,v)
- ...
- marron brown
- rojo red
- gris grey
- blanco white
- colorado red
- >>> frase = "soy una frase"
- >>> len(frase)
- 13
- >>> frase.endswith("se")
- True
- >>> frase.endswith("ce")
- False
- >>> frase.startswith("ce")
- False
- >>> frase.upper()
- 'SOY UNA FRASE'
- >>> frase.swapcase()
- 'SOY UNA FRASE'
- >>> frase.lower()
- 'soy una frase'
- >>> frase = "jkjKOKKKKñññ"
- >>> frase.swapcase()
- 'JKJkokkkkÑÑÑ'
- >>> frase
- 'jkjKOKKKKñññ'
- >>> frase.lower()
- 'jkjkokkkkñññ'
- >>> frase
- 'jkjKOKKKKñññ'
- >>> frase = "HOLA a todos"
- >>> frase.lower()
- 'hola a todos'
- >>> frase.upper()
- 'HOLA A TODOS'
- >>> frase.swapcase()
- 'hola A TODOS'
- >>> frase
- 'HOLA a todos'
- >>> frase = frase.swapcase()
- >>> frase
- 'hola A TODOS'
- >>> frase[-1]
- 'S'
- >>> frase[0]
- 'h'
- >>> lista
- [253, 12, 0.002, -0.25, -256]
- >>> lista[1:]
- [12, 0.002, -0.25, -256]
- >>> lista[1:-1]
- [12, 0.002, -0.25]
- >>> lista[1:-1:2]
- [12, -0.25]
- >>> frase
- 'hola A TODOS'
- >>> frase[:]
- 'hola A TODOS'
- >>> frase[:-1]
- 'hola A TODO'
- >>> frase[2:-2]
- 'la A TOD'
- >>> lista
- [253, 12, 0.002, -0.25, -256]
- >>> a,b,c,d,e=lista
- >>> a
- 253
- >>> b
- 12
- >>> c
- 0.002
- >>> d
- -0.25
- >>> e
- -256
- >>>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement