Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,195,459 members, 7,958,379 topics. Date: Wednesday, 25 September 2024 at 01:33 PM |
Nairaland Forum / Science/Technology / Programming / Common good python programming practices you should know (13423 Views)
A Thread For Tutorial On Python Programming / A Very Good Python Programmer Needed Asap / Recommend A Good Python Data Mining Book (2) (3) (4)
(1) (2) (3) (4) (5) (6) (7) (8) (Reply) (Go Down)
Re: Common good python programming practices you should know by gbolly1151(m): 12:39pm On Jan 01, 2020 |
|
Re: Common good python programming practices you should know by gbolly1151(m): 8:10am On Jan 07, 2020 |
|
Re: Common good python programming practices you should know by gbolly1151(m): 7:12pm On Jan 08, 2020 |
|
Re: Common good python programming practices you should know by gbolly1151(m): 12:32pm On Jan 13, 2020 |
|
Re: Common good python programming practices you should know by gbolly1151(m): 8:29pm On Feb 03, 2020 |
Wanna quickly drop this: NAMING IN PYTHON ACCORDING TO PEP -To name a class,start with Capital letters (preferably a noun). if multiple words,use CamelCase e.g class PersonalData -To name a function start with small letters (preferably a verb,demonstrating the kind of action the function perform). if multiple words, use underscore e.g def get_name -parameters of class or function should be in small letters -If constant variables are in your program,indicate the name in capital letters and use underscore if multiple words e.g PADDING_NUM |
Re: Common good python programming practices you should know by gbolly1151(m): 9:06am On Mar 21, 2020 |
It been a while here,school has kept me busy for a while but with this coronavirus holiday let see what we can learn 1 Like |
Re: Common good python programming practices you should know by gbolly1151(m): 9:48am On Mar 21, 2020 |
What are private and protected variable? Java programmers must understand those two keywords but for python programmer let me quickly explain them and how you can implement them in python. Private variable are variable that can only be called within the class scope, a call from outside will throw an error Protected variable are variable that can be called by the class and subclasses only. In python,protected variable definition is not true but normal convention of creating it, is to start variable name with single underscore (e.g _name). Loophole we have in python is that this single underscore variable can be called from anywhere unlike java and c++ in which protected variable name can only be called by class and subclasses. The private variable can be created using double underscore (e.g __name) and it is the one that work well with the definition in python.it can only be class within the class or function that create the variable
This protected and private variable are used to hid the internal working of your code sometime from users. |
Re: Common good python programming practices you should know by yemyke001(m): 9:59pm On Mar 21, 2020 |
Weldone boss.. Please we await more of your tutelage. It's really making sense! 1 Like |
Re: Common good python programming practices you should know by gbolly1151(m): 10:49pm On Mar 21, 2020 |
yemyke001: Thanks boss for the compliment... I will always do my best 2 Likes |
Re: Common good python programming practices you should know by gbolly1151(m): 9:32am On Mar 24, 2020 |
Good morning To become a good programmer is not about knowing syntax is about how you structure your data and low time execution of your algorithm on large input, so continue mastering data structure and algorithm to become a good programmer |
Re: Common good python programming practices you should know by scarplanet(m): 11:22am On Mar 24, 2020 |
When you can handle functions and classes effectively, only then can you say you have made great strides in Python. Learn as much Python libraries as you can. Libraries can improve your algorithm's time and space complexity 1 Like |
Re: Common good python programming practices you should know by gbolly1151(m): 6:45pm On Mar 24, 2020 |
Guys here is a little project i just play with using django as backend and bootstrap as frontend /mydemoapp12345.herokuapp.com/ remove first and last slash |
Re: Common good python programming practices you should know by gbolly1151(m): 11:28pm On Mar 27, 2020 |
Recursion is quite tricky and most programmer find it difficult to understand, in this post am going to try all my possible best to simplify the logic of this term. Recursion in programming is a way of a function to call itself #Example 1
Note: that if you initialize the function,you will end up with error,i will tell you why later example 1 above is a recursion because the function add call itself (i.e add(n-1)) inside it own function. If you run add(4) here is explanation on how it going to run: 1.when add(4) call get to return,it will call add(4-1) i.e add(3). since add(4) return is calling a function add(3), it will wait still the function add(3) finish execution 2.add(3) will run still it get to line with return where it going to call (add(3-1)) i.e add(2). add(3) will Wait still add(2) finish execution too 3. add(2) will run until it get to return where it call add(2-1) i.e add(1), this let add(2) return to Wait for add(1) execution 4. This continue for add(0), add(-1), add(-2), add(-3) still recursive stack get filled up probably add(-496) where it throw error because that is the maximum call that can be made for recursive when it can't run further. Then how are will going to control it? A way of controlling the call is through conditional statement. IMPORTANT KEY TO KNOW IS THAT EVERY RECURSIVE FUNCTION MUST HAVE A CONDITION TO STOP THE CALL Now let modify our example
if n <= 1: return 1 ,will help us to stop add() call at n == 1 Here is how it will run 1.add(4) will call add(4-1) i.e add(3),which will call add(3-1) i.e add(2) 2.when getting a call for add(1),it will return 1 and no call will be made again Now let modify our example to add numbers from 1 to n where n is positive integers
Here is what happen behind the scene 1. add(4) return 4 + add(4-1) i.e add(3) ( output is 4 + add(3)) 2. add(3) call return 3 + add(3-1) i.e add(2) ( output is 3 + add(2)) 3. add(2) call return 2 + add(2-1) i.e add(1)( output is 2 + add(1) ) 4. add(1) call return 1 Technically add(4) wait till there is no call i.e when n == 1 which stop the call Now add(4) call return 4 + 3 + 2 + 1 = 10 This bring us to the end of recursion, try to read again and digest then start building on it....if you have any question just drop them. 1 Like 1 Share |
Re: Common good python programming practices you should know by gbolly1151(m): 8:42pm On Mar 31, 2020 |
HOW TO CHECK RUNNING TIME OF YOUR SCRIPT After writing a long script, it is a good practice to check the running time of your script with numbers of input for optimization. There is a module in python for this purpose called cProfile, so let write some code and check the running time
Check the output in the pic below let define those column ncalls : numbers of calls made by the function tottime : total time taken for the function to excecute percall : tottime/ncall cumtime : commulative time for all the calls made on the function percall : quotient of cumtime divided by primitive calls filename lineno(function) : filename is the name of the file(eg test.py), lineno(eg lineno for import cProfile is 7), function is the name of function 1 Share
|
Re: Common good python programming practices you should know by Grandlord: 9:28pm On Mar 31, 2020 |
gbolly1151:Nice one. 1 Like |
Re: Common good python programming practices you should know by gbolly1151(m): 11:37pm On Mar 31, 2020 |
Let me quickly drop
|
Re: Common good python programming practices you should know by gbolly1151(m): 4:49pm On Apr 01, 2020 |
CONDITIONAL EXPRESSION conditional expression help to assign a value to a variable based on a given condition. the syntax is var=expr1 if condition else expr2
|
Re: Common good python programming practices you should know by gbolly1151(m): 6:27pm On Apr 02, 2020 |
TIP TO LEARN OOP To master OBJECT ORIENTED PROGRAMMING (OOP) start with CLASS DIAGRAM in UNIFIED MODELING LANGUAGE (UML),it will really help to know relationship between classes and make code writing easy. 1 Like 1 Share |
Re: Common good python programming practices you should know by gbolly1151(m): 5:31pm On Apr 04, 2020 |
iter() and next() KEYWORD Iter() - is just used to make an object iterable,iterable objects are use for forloop operation. this keyword call __iter__() method from the object, if not available then it throw error next() - this keyword is use to access __next__() method of the object inbuit data type that has this method are list,dictionary,set and tuple With that you can make your class iterable e.g let create a data type that return reverse of the any string
2 Likes 1 Share |
Re: Common good python programming practices you should know by gbolly1151(m): 11:18pm On Apr 05, 2020 |
Difference between yield and return i will explain generator before going into yeild and return; generator is a class that help to transform any object to work with iter() and next() Now what are yield and return? Both keywords are used in returning value from a function but in different ways, yield 1) release a generator object that called iter() method i.e (yield = return genertor(object).__iter__()) and also 2) pause a function(it keep the state of function),then resume action when next() is called return only help to terminate a function and release a value. '''
1 Share
|
Re: Common good python programming practices you should know by Nobody: 12:38pm On Apr 06, 2020 |
I don't even understand a thing from here. Nnaa ehn |
Re: Common good python programming practices you should know by gbolly1151(m): 7:06pm On Apr 06, 2020 |
locust:Which part and are you just learning python? |
Re: Common good python programming practices you should know by Nobody: 7:18pm On Apr 06, 2020 |
gbolly1151: Confused on which one to learn first; Java, python, Django, c# and the rest. I'm a rookie. 1 Like |
Re: Common good python programming practices you should know by gbolly1151(m): 9:05pm On Apr 06, 2020 |
locust: Those tips are advance anyway but i will advice you to pick up on one and learn,master it,then you can move on easily with other programing language. |
Re: Common good python programming practices you should know by Playforkeeps(m): 8:39pm On Apr 08, 2020 |
What im about to share isnt necessary a Practice, think of it as a tip. And it is how to setup a simple file server in python to be accessed by any client in your LAN. All you have to do is cd into the Server root directory and run <code> python3 -m http.server <code/> that will start a server on default port 8000 and if thats not suitable for you, you can pass in a custom port as an argument to the command. 1 Like |
Re: Common good python programming practices you should know by gbolly1151(m): 7:58am On Apr 09, 2020 |
Playforkeeps:Nice one |
Re: Common good python programming practices you should know by Playforkeeps(m): 10:20am On Apr 09, 2020 |
gbolly1151:Thanks man, you’re doing a great job here man, we need more active Python/Django communities 1 Like |
Re: Common good python programming practices you should know by gbolly1151(m): 12:24pm On Apr 09, 2020 |
Playforkeeps:True...i am hoping to create a Nigerian forum for it |
Re: Common good python programming practices you should know by gbolly1151(m): 12:24pm On Apr 09, 2020 |
Try and Except keyword This is a wonderful keyword for controlling error output in python. for example: on a norm,dividing a number by 0(zero) is mathematical error,so if you try to divide 2//0 in python,an awful error will be printed out like this below,which cant be easily understood by user.
using Try and except keyword, you can control the output and print out your desire output let create two functions for out zero division error; 1.with try and except 2.without try and except
below pic show that,div1() give a nice output to the console than div2() thanks to try and except for the job 1 Share
|
Re: Common good python programming practices you should know by gbolly1151(m): 3:15pm On Apr 09, 2020 |
Tip for learning software development Pick up python design patterns and learn |
Re: Common good python programming practices you should know by gbolly1151(m): 8:56pm On Apr 12, 2020 |
HOW TO GENERATE ENGLISH ALPHABET The keyword for this task is chr() which take in number as argument and return equivalent character. E g chr(97) return 'a',with this we can generate our 26 English alphabet
For capital letters start from 65 1 Like 1 Share |
Re: Common good python programming practices you should know by gbolly1151(m): 7:38pm On Apr 14, 2020 |
I have started another thread,you can follow Tutorial: Object Oriented Programming Paradigm For Beginners |
(1) (2) (3) (4) (5) (6) (7) (8) (Reply)
What Attracted You To Learn how to code? / In What Order Did You Learn Your Languages? / Where Is That Female Geek: Any Good Female Developer Around?
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 65 |