๐—ฃ๐—˜๐—ฃ-๐Ÿด

-Want to write an "Eye-pleasing" Python code ๐Ÿ ๐Ÿ‘€?

-PEP is a thing you MUST know about while learning or writing a python code

-Python Enhancement Proposal

-Basically a guide to "๐—›๐—ผ๐˜„ ๐˜๐—ผ ๐˜„๐—ฟ๐—ถ๐˜๐—ฒ ๐—ฎ ๐—ฏ๐—ฒ๐—ฎ๐˜‚๐˜๐—ถ๐—ณ๐˜‚๐—น ๐—ฝ๐˜†๐˜๐—ต๐—ผ๐—ป ๐—ฐ๐—ผ๐—ฑ๐—ฒ?"

BIG Thread ๐Ÿงต๐Ÿ‘‡
We all know that besides having logic and coding in any programming language, there is an important factor that is "coding style"

-How we are writing comments?
-How we are giving spaces?
-How to import libraries?
-etc

These things are very important to write a beautiful code!
For Python, PEP 8 has emerged as the style guide that most projects adhere to.

It promotes a very readable and "eye-pleasing" coding style. ๐Ÿ˜

A code which anyone will love to read and is very easily understandable.
Further in this thread ๐Ÿงต

I am going to explain some important points of PEP-8, which are important to write a beautiful code in Python๐Ÿ
๐— ๐—ฎ๐˜…๐—ถ๐—บ๐˜‚๐—บ ๐—Ÿ๐—ถ๐—ป๐—ฒ ๐—Ÿ๐—ฒ๐—ป๐—ด๐˜๐—ต ๐Ÿ”ข

Limit all lines to a maximum of 79 characters.

For docstrings or comments, the line length should be limited to 72 characters.

In long with statements, "/" are acceptable otherwise break it and continue in the next line.

๐Ÿ”—Example
๐—œ๐—ป๐—ฑ๐—ฒ๐—ป๐˜๐—ฎ๐˜๐—ถ๐—ผ๐—ป๐Ÿ”

-Use 4 spaces for indentation

-Add 4 spaces (extra level of indentation) to distinguish arguments from the rest

-Spaces are the preferred indentation method

-Tabs should be used solely to remain consistent with code that is already indented with tabs!
๐—–๐—ผ๐—บ๐—บ๐—ฒ๐—ป๐˜๐˜€๐Ÿ—ฏ๏ธ

- Comments that contradict code are worse than no comments

- Never use comments in a place where it is not needed

-Comments are indented to the same level as that code.

-Each line of a block comment starts with a # and a single space
๐——๐—ผ๐—ฐ๐˜‚๐—บ๐—ฒ๐—ป๐˜๐—ฎ๐˜๐—ถ๐—ผ๐—ป ๐—ฆ๐˜๐—ฟ๐—ถ๐—ป๐—ด๐˜€ ๐Ÿ“„

-Conventions for writing good documentation strings (a.k.a. "docstrings") are immortalized in PEP 257.

-Write docstrings for all public modules, functions, classes, and methods.

-Docstrings are not necessary for non-public methods
๐—•๐—น๐—ฎ๐—ป๐—ธ ๐—Ÿ๐—ถ๐—ป๐—ฒ๐˜€ ๐Ÿ”ณ

-Surround top-level function and class definitions with two blank lines.

-Method definitions inside a class are surrounded by a single blank line.

-Use blank lines in functions, sparingly, to indicate logical sections.
๐—œ๐—บ๐—ฝ๐—ผ๐—ฟ๐˜๐˜€ โœ…

-Should be on different lines

-Should be on the top

-Grouped in the following order
-Standard library imports
-Related third-party imports
-Local application/library specific imports

-You should put a blank line between each group of imports
This whole thread is NOT the complete PEP-8 style guide, but these are the most important points from it!!

You can write an eye-pleasing python code that everyone wants to read If they see the code!

You can access the complete PEP-8 guide here ๐Ÿ‘‡

๐Ÿ”— python.org/dev/peps/pep-0โ€ฆ
Hey,

Thanks for coming to the end of the thread โค๏ธ

I hope, you understand what PEP is and how to write a beautiful python code :)

If you like this thread, Retweet the first tweet of the thread.

So that we all can learn about it!!

โ€ข โ€ข โ€ข

Missing some Tweet in this thread? You can try to force a refresh
ใ€€

Keep Current with Saurav Jain

Saurav Jain Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @Sauain

21 Jul
Five NumPy Functions a beginner should know about๐Ÿ๐ŸŒŸ

๐Ÿงต๐Ÿ‘‡ Image
1โƒฃ ๐—ป๐—ฝ.๐—ฎ๐—ฟ๐—ฟ๐—ฎ๐˜†

In Numpy, we create arrays using the "array" function.

Numpy gives the power to create multi-dimensional arrays.

๐Ÿ”— Code Image
2โƒฃ ๐—ป๐—ฝ.๐˜€๐—ต๐—ฎ๐—ฝ๐—ฒ

The shape of an array is the number of elements in each dimension.

NumPy arrays have an attribute called shape that returns a tuple with each index having the number of corresponding elements.

๐Ÿ”— Code Image
Read 7 tweets
19 Jul
๐—ฅ๐—ฒ๐—ถ๐—ป๐—ณ๐—ผ๐—ฟ๐—ฐ๐—ฒ๐—บ๐—ฒ๐—ป๐˜ ๐—น๐—ฒ๐—ฎ๐—ฟ๐—ป๐—ถ๐—ป๐—ด ๐Ÿค–

-A type of Machine Learning (What is it?)
-It's working
-Real-life Applications
-A book for learning RL
-Limitations

Let's learn about all these things in this thread!!

๐Ÿงต๐Ÿ‘‡
๐—ช๐—ต๐—ฎ๐˜ ๐—ถ๐˜€ ๐—ฅ๐—ฒ๐—ถ๐—ป๐—ณ๐—ผ๐—ฟ๐—ฐ๐—ฒ๐—บ๐—ฒ๐—ป๐˜ ๐—น๐—ฒ๐—ฎ๐—ฟ๐—ป๐—ถ๐—ป๐—ด?

- A machine learning area.

-In RL an ML model is trained to take a sequence of decisions.

-If the model takes a correct decision it will get awarded otherwise negative points will be given.

Perfect Explanation๐Ÿ‘‡
๐—ช๐—ผ๐—ฟ๐—ธ๐—ถ๐—ป๐—ด

Environment: Physical world in which the agent operates

State: Current situation of the agent

Reward: Feedback from the env.

Policy: Method to map agentโ€™s state to actions

Value: Future reward that an agent would receive by taking an action in particular state
Read 9 tweets
14 Jul
๐—›๐—ฎ๐—ฎ๐—ฟ ๐—–๐—ฎ๐˜€๐—ฐ๐—ฎ๐—ฑ๐—ฒ๐˜€๐Ÿ‘จโ€๐Ÿ’ป

- Arguably OpenCVโ€™s ( Open source Computer Vision ) most popular object detection algorithm.

-What is it?
-Algorithm
-Limitation
-Applications

A BIG Thread ๐Ÿงต๐Ÿ‘‡
We are living in an era, where object detection is used everywhere.

From security cameras to our mobile phones, it is used everywhere.

Haar classifiers, classifiers were used in the ๐—ณ๐—ถ๐—ฟ๐˜€๐˜ ๐—ฟ๐—ฒ๐—ฎ๐—น-๐˜๐—ถ๐—บ๐—ฒ ๐—ณ๐—ฎ๐—ฐ๐—ฒ ๐—ฑ๐—ฒ๐˜๐—ฒ๐—ฐ๐˜๐—ผ๐—ฟ.
๐—ช๐—ต๐—ฎ๐˜ ๐—ถ๐˜€ ๐—›๐—ฎ๐—ฎ๐—ฟ ๐—–๐—ฎ๐˜€๐—ฐ๐—ฎ๐—ฑ๐—ฒ โ”

Haar Cascade classifiers are an effective way for object detection.

This method was proposed by Paul Viola and Michael Jones in their paper Rapid Object Detection using a Boosted Cascade of Simple Features.
Read 13 tweets
13 Jul
Learn Python while playing games ๐ŸŽฏ

Five Ideas to make a game using Python๐Ÿ

๐Ÿงต
1โƒฃ Dice Roller

Have no dice for your ludo game?

No worries you can create one using Python in just a few minutes.

Just use a random library and make one for yourself๐Ÿ˜‰
2โƒฃ Hangman

You can make this game in Python too ;)

The word to guess is represented by a row of dashes.

If the player guesses a letter that exists in the word, the script writes it in all its correct positions. The player has 10 turns to guess the word.
Read 7 tweets
12 Jul
Seven Python Math Library Functions ๐Ÿงฎ ๐Ÿ

A beginner should know about these important functions, it will make your work easy!!

Thread ๐Ÿ˜๐Ÿงต Image
1โƒฃ ๐˜€๐—พ๐—ฟ๐˜

In python, to find the square root of any number ( 3 is the square root of 9 ) you don't have to use power operator.

There is a special function " sqrt " which square roots the number given it as a parameter :)

๐Ÿ”— Code Image
2โƒฃ ๐—ฝ๐—ผ๐˜„

In the above tweet, we have learned how to square root a given number.

A square root is actually a number raised to a power of 0.5

But what if we want 3 or something as power.

Here we use " pow(x,y) " it returns x raised to power y.

๐Ÿ”— Code Image
Read 9 tweets
10 Jul
Five Python Libraries for Machine Learning ๐Ÿ

Thread ๐Ÿงต๐Ÿ‘‡
1โƒฃ ๐—ง๐—ฒ๐—ป๐˜€๐—ผ๐—ฟ๐—™๐—น๐—ผ๐˜„

It is an open-source library created by the Google Brain team.

It is very popular for high-performance numerical computation.

It has an ecosystem of tools, libraries, and community resources for building and deploying powerful ML applications.
2โƒฃ ๐—ž๐—ฒ๐—ฟ๐—ฎ๐˜€

Keras is a deep learning API written in Python, running on top of the machine learning platform TensorFlow.

It is a high-level neural networks API capable of running on top of TensorFlow, CNTK, or Theano.

It can run seamlessly on both CPU and GPU.
Read 7 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!

Follow Us on Twitter!

:(