How I can learn and undesrtand deeply about Functions? | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
+ 4

How I can learn and undesrtand deeply about Functions?

I am a new one in python and i just know greeting in it. I am able to use def to write some easy and simple codes but to be honest with myself, I couldnt undesrtand it deeply. could you plz allow me to understand it better and deep? when a code is long, i get confused and dunno how functions are related together! Thanks in advance for any help

4th Oct 2017, 4:56 PM
Shabnam
Shabnam - avatar
14 Antworten
+ 15
Dear Shabnam I've been in this situation 6 years ago when I was a CS student. I was messing around with language facilities blindly without any solid understanding of what's really going on behind the scene. But soon, through math courses (helped me to understand what a function is in its abstract form) and doing a lot of homework assignments and little projects by try and error ( of course, doing a lot of dumb mistakes!), became familiar with this REALLY SIMPLE concept. It's inevitable to skip the learning curve, but hopefully, we will see your improvement inch by inch through your determination and will power. Good luck my friend. @~)~~~~
4th Oct 2017, 8:36 PM
Babak
Babak - avatar
+ 15
Hi again Shabnam Here is a youtube channel about the basic concepts of Python. [https://www.youtube.com/watch?v=D48iCw3WWpI&list=PL82YdDfxhWsDJTq5f0Ae7M7yGcA26wevJ] You can download the function related part from here. [https://www.mediafire.com/file/5ai80z9s4qufx9w/Let%27s_Learn_Python_-_Basics_%236_of_8_-_Functions.mp4]
5th Oct 2017, 8:58 AM
Babak
Babak - avatar
+ 14
Don't worry dear. You don't need to be great to start something, but you need to start to be great. Very soon you'll figure out how to walk and run in programming rather than crawling. ;)
4th Oct 2017, 9:00 PM
Babak
Babak - avatar
+ 5
منظورم از مستندات همون help هستش. بزار اینجوری بگم شاید راحت تر باشه...من ماهیتو میگم به کد پایتون کار ندارم. من یکسری کار دارم که ممکنه هی تکرار بشه ... اگه بخوام این رو صدبار بنویسمش اولا کدهام شلوغ میشه دوما کدهام نگهداریش سخت میشه.... میان تابع تعریف میکنم تا دیگه کد تکراری ننویسم و اگه قرار تابع. خروجی من تغیر داشته باشه یه جا رو دستکاری کنم نه صد خط کد رو مثلا. من باید 100 بار برای اندازه های مختلف مستطیلهای مختلف مساحت حساب کنم rec1=x1+y1 rec2=x2+y2 rec3=.... . . . rec100=x100+y100 عجب افتضاحی من مساحت میخواستم حساب کنم به جای ضربدر بعلاوه گذاشتم ....حالا باید برم این صد خط کد رو اصلاح کنم . اما اگه تابع بود مثل زیر function RectSurface(int x,int y) { return x+y } rec1=RectSurface(x1,y1) rec2=RectSurface(x2,y2) rec3=RectSurface(x3,y3) . . . rec100=RectSurface(x100,y100) درسته که باز تابع من داره اشتباها جمع میزنه ولی خوب من الان بجای صد خط کد فقط همون جمع داخل تابع رو بکنم ضرب درست میشه ...یعنی فقط یه جا اصلاح شد نه مثل قبلی صد جا مثال یکم کوچیکه چون الان میگی خوب تابع نوشتنه یه چهار پنج خط بیشتره از بدون تابع نوشتنه نه اینجوری نیست تابع من کار یه خطی میکنه اگه برای هر متغیر باید. یه کد بیست خطی مینوشتم تو حالت بدون تابع صد تا متغییر دارم که xبیست میشه 2000 خط کد ولی با تابع میشه یه بیست خط بعلاوه 100 خط فراخوانی تابع که میشه 120 خط... static void main(ref int a, out int b) { return a×b; } به استاتیک میگن اaccess modifier اسم تابع من main هست پارامتر ورودی a,b هست پارامتر خروجی anonymous هست ولی return این کار رو میکنه و خروجی رو میده مودیفایر ref از نوع refrence value type میکنتش و out خروجی با تغییر میده این کد بالا سینتکس زبان سی شارپه ولی همه زبانها این شکلین و ماهیتشان یکیه هرجای حرفامو متوجه نشدی کافیه تو اینترنت بگردی ...خودتو به پایتون محدود نکن ..ماهیتو درک کنی دیگه زبان واست اهمیت نداره واسه همینه میگن اگه یه زبان یاد بگیری بقیه زبانها راحت میشه برات ببخشید زیادی نوشتم و حوصله سر بر شد
4th Oct 2017, 5:58 PM
Sayid Yarmohammadi
Sayid Yarmohammadi - avatar
+ 4
بهترین راه خوندن مستندات خود زبانه .... به ساده ترین و کاملترین طریقه ممکنه یاد میده اصلا ماهیت تمام زبان های برنامه نویسی یکیه و تقریبا تمام کلمات کلیدی شون یکیه مگر دیگه جزء ویژگی اون زبان باشه که تو بقیه نباشه ولی خوب خود همین ویژگی به طرقی در زبان های دیگه قابل پیاده سازی خواهد بود.... توابع هم. از این موضوع مستثنا نیستن ... یکم بیشتر کار کنی کامل دستت میاد
4th Oct 2017, 5:26 PM
Sayid Yarmohammadi
Sayid Yarmohammadi - avatar
+ 3
A function in python is just a list of instructions(code) that is encapsulated under a name you can call as many times as you want. This is useful because there are snippets of code or things you want to do many times in a program, so you would call the appropriate function to do the given task. Sure, you could just rewrite your code to do the same thing, but there's a saying in computer science: Never copy-paste code. Because it duplicates bugs and edits you'll have to make. It sounds like common sense, but many programmers out there forget that. If you're still confused, post back.
4th Oct 2017, 5:19 PM
Sapphire
+ 3
dear @sapphire thank u so much for your answer. I appreciate it. U know I know about function a little bit but i cant understand how and when to call it. I also cant relate functions to each other. So if i cant it means I didnt understand it well unfortunately.
4th Oct 2017, 5:29 PM
Shabnam
Shabnam - avatar
+ 3
آقای سعید گرامی خیلی تشکر میکنم از شما. منظورتون از مستندات چی هست؟ من چند کتاب گرفتم روی وبسایت های مختلف کم و بیش کار میکنم و اصلا ریاضی من خوب که نیست بد هم هست. ولی من گویا درونم به کد علاقه داره. متاسفانه قسمت فانکشن رو نتونستم درک کنم و اصلا نمیدونم چرا. مثلا وقتی دو تا فانکشن بشه من گیج میشم و کاربردش کلا برام گیج کننده میشه. من متوجه شدم که من اصلا متوجه نشدم! و حالا دنبال یک تعریف یا هر چیزی هستم که این رو برام واضح بکنه. بازم خیلی از شما تشکر میکنم و از داشتن هر نظری از جانب شما خوشحال میشم. @sayid yarmohammadi
4th Oct 2017, 5:33 PM
Shabnam
Shabnam - avatar
+ 3
جناب آقای سعید واقعا از وقتی که برام گذاشتید یک دنیا تشکر میکنم بینهایت سپاسگذارم. لطف کردید. چشم کاری که میفرمایید انجام میدم. و بسیار توضیح جانانه ای بود.
4th Oct 2017, 6:05 PM
Shabnam
Shabnam - avatar
+ 3
موفق باشید
4th Oct 2017, 6:05 PM
Sayid Yarmohammadi
Sayid Yarmohammadi - avatar
+ 2
Dear Babak, thank u sooo much. It made me feeling relax coz It seems I am on the way which is not just confusing for me and how one can improve little by little. coz my main major is biology and my knowlege in math is kinda much in low level,(i can say i have no knowledge in math but i feel i am good in coding or maybe its a motivation in me for codes ...), maybe the reason I have problem in undesrtanding basics and meanings is exactly here, Math!! Thank you so much for ur message which is like a hope gift card to me. I appreciate it
4th Oct 2017, 8:43 PM
Shabnam
Shabnam - avatar
+ 2
Yes I just must keep going and dont leave the way. You are true and I agree with you however the first step is always difficult. Dear Babak, thank you for your beautiful reply.
4th Oct 2017, 9:02 PM
Shabnam
Shabnam - avatar
+ 2
والا خوبه
5th Oct 2017, 9:03 AM
Amir Abdolmaleki
Amir Abdolmaleki - avatar
+ 2
awww a big suprise to me dear Babak. thank you so much for your kindness. Im ganna check the links. again and again thanks a million for your great help
5th Oct 2017, 10:34 AM
Shabnam
Shabnam - avatar