Специальная, подарочная акция получения доступа к Django4!
Как, я, начал код писать в Python? Смотрите, если уперлись и ничего не получается.
31 урок. **kwargs python развернутый урок.
# -*- coding: utf-8 -*-
def funfun(a, b, c, d): """ if/else try/exept """ a = "" b = {key: value} c = [] d = () return a, b, c, d
funfun()
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-3-2780c3cecac3> in <module> ----> 1 funfun() TypeError: funfun() missing 4 required positional arguments: 'a', 'b', 'c', and 'd'
funfun('', {}, [], ())
class Person: name = "valery" # метод def print_info(self): print("меня зовут, ", self.name)
person2 = Person()
person2.print_info()
# Строка a = "" # словарь b = {'key': 'value'} # список c = [] # картеж d = () #числа 2 массив
2
""" объект послеловательность list = [] strings = "" tuple = () dict = {ключ:значение} fun strit(hause): hause = [] """
print(type(funfun))
<class 'function'>
dir(type)
['__abstractmethods__', '__base__', '__bases__', '__basicsize__', '__call__', '__class__', '__delattr__', '__dict__', '__dictoffset__', '__dir__', '__doc__', '__eq__', '__flags__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__instancecheck__', '__itemsize__', '__le__', '__lt__', '__module__', '__mro__', '__name__', '__ne__', '__new__', '__prepare__', '__qualname__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasscheck__', '__subclasses__', '__subclasshook__', '__text_signature__', '__weakrefoffset__', 'mro']
list2 = [] strings2 = "" tuple2 = () dict2 = {'ключ':'значение'}
print(type(list2))
<class 'list'>
list3 = []
dir(list3)
['__add__', '__class__', '__class_getitem__', '__contains__', '__delattr__', '__delitem__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__iadd__', '__imul__', '__init__', '__init_subclass__', '__iter__', '__le__', '__len__', '__lt__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__reversed__', '__rmul__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', 'append', 'clear', 'copy', 'count', 'extend', 'index', 'insert', 'pop', 'remove', 'reverse', 'sort']
dir(funfun)
['__annotations__', '__call__', '__class__', '__closure__', '__code__', '__defaults__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__get__', '__getattribute__', '__globals__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__kwdefaults__', '__le__', '__lt__', '__module__', '__name__', '__ne__', '__new__', '__qualname__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__']
funfun.__doc__
'\n if/else\n try/exept\n \n '
list3 = [] strings3 = "" tuple3 = () dict3 = {'ключ':'значение'}
print(type(list3))
print(type(strings3)) print(type(tuple3)) print(type(dict3))
<class 'str'> <class 'tuple'> <class 'dict'>
a = dict(one=1, two=2, three=3) b = {'one': 1, 'two': 2, 'three': 3} c = dict(zip(['one', 'two', 'three'], [1, 2, 3])) d = dict([('two', 2), ('one', 1), ('three', 3)]) e = dict({'three': 3, 'one': 1, 'two': 2}) f = dict({'one': 1, 'three': 3}, two=2)
list(d)
['two', 'one', 'three']
list(c)
['one', 'two', 'three']
a == b == c == d == e == f
True
dict4 = {}
def funfun2(*args, **kwargs): """ if/else try/exept """ a = "" b = {'key': 'value'} c = [] d = () return a, b, c, d
funfun2()
--------------------------------------------------------------------------- NameError Traceback (most recent call last) <ipython-input-42-f799b17b1589> in <module> ----> 1 funfun2() <ipython-input-41-dc7dbd2f1589> in funfun2(*args, **kwargs) 6 """ 7 a = "" ----> 8 b = {key: value} 9 c = [] 10 d = () NameError: name 'key' is not defined
def funfun3(*args, **kwargs): """ if/else try/exept """ a = "" # ключ/значение определны. как строки b = {'key': 'value'} c = [] d = () return a, b, c, d
funfun3()
('', {'key': 'value'}, [], ())
def fun4(der, der2): pass
fun4()
--------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-50-ae459c2090ec> in <module> ----> 1 fun4() TypeError: fun4() missing 2 required positional arguments: 'der' and 'der2'
Вcе записи подраздела.
Сейчас вы проходите урок: 31 урок. **kwargs python развернутый урок.
<< Назад | Далее >>
Все уроки с тегом: функции-python