Python Tutorial for Absolute Beginners - #8 Functions
Learn programming in Python 100 seconds at a time in this tutorial for absolute beginners. This is video number 8: Functions
I know im going fast in this video, please use timestamps below to navigate the video.
Timestamps:
00:00 - Start
00:43 - Positional Arguments
01:01 - Keyword Argument
01:13 - pre-defined parameter
01:23 - function argument error
01:30 - return statement
01:39 - optional argument
—————————————————————
FUNCTIONS
—————————————————————
A function is a block of code that is written for a specific job
The function can be called by using the name of the function
Here’s an example
First define the name of the function with the ‘def’ statement
The next line is the actions of the function
This can by any action, but the print function is used as an example
Def car_info():
print(“I drive an Audi”
car_info()
The last line is the call to a function
Notice how the function has brackets on the end.
Between the brackets a variable can be defined Which is used inside the function
A variable inside a function is called a parameter
Between the brackets, Inside the call function, the information to store in a parameter is defined
The information inside a call to a function is called an argument
Def car_info(car)
print(“I drive and “ + car)
car_info(“Audi”)
You can use multiple parameters inside a function.
When arguments inside a call need to be passed in a certain order
They are called positional arguments
If the order of arguments passed to a function isn’t the same as the order of parameters
The function will still be executed
But will cause a so called logical error
Because the output is not what is expected DOUBLE CHECK DEFINITION LOGICAL ERROR
Def car_info(name, car):
print(“My “ + name + “ is and I drive an “ + car)
car_info’John’,’Audi’)
print(“”)
car_info(‘Audi’,’John’)
To avoid sticking to an order, pass a ‘keyword argument’ inside the call.
A keyword argument is a name-value pair, which directly links the argument to the parameter inside a function allowing to ignore the order inside a function
Def car_info(name, car)
print(“My “ + name + “ is and I drive an “ + car)
car_info(car=‘Audi’, name=’John’)
Let’s say a parameter inside a function always has specific value
Then the argument can be stored directly inside the function
Both print functions work
Def car_info(name, type=‘Audi’)
print(“My “ + name + “ is and I drive an “ + car)
car_info(name=’John’)
car_info(‘John’)
When you don’t pass arguments, python will return an error
Def car_info(name, car)
print(“My “ + name + “ is and I drive an “ + car)
car_info(‘John’,’Audi’)
print(“”)
car_info()
Python actually tells you that it’s not just missing arguments
But it’s missing two arguments
The return statement inside a function is used to have all the work done by the function
But the result is not shown directly
Rather the result can be called where intended
Def car_info(name, type)
statement = “My “ + name + “ is and I drive an “ + car
return statement
driver = car_info(‘John’,’Audi’)
print(driver)
An argument can be optional, by making use of the if statement inside the function
Here the function looks if that argument is passed to the function from the call
If it is, it includes that argument, if it’s isn’t then it won’t
Def car_info(name, car, type)
if type:
statement =“My “ + name + “ is and I drive an “ + car + “ “ + type
else:
“My “ + name + “ is and I drive an “ + car
return statement
driver = car_info(‘John’,’Audi’)
print(driver)
driver = car_info(‘John’,’Audi, RS4’)
print(driver)
————————————————————————
? Who are you?
My name is Raza. I am 30. I am a manager within IT for a year, but I’ve been an accountant for the majority of my career.
I’m in love with #Python :)
You can find me here:
? Instagram: https://www.instagram.com/razacodes/
? Twitter: https://twitter.com/razacodes
—————————————————————————————
Goals for 2021
Training Python hours: 40/1000
Python/Django Projects: 1/30
Subscribers: 1446/10,000
—————————————————————————————-
#100SecondsOfCode
#pythonforbeginners #programming
Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «Python Tutorial for Absolute Beginners - #8 Functions», вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.
Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.
Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!
Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.