A.I, Data and Software Engineering

Advanced python part 1


Let get some more advanced python techniques, tools, libraries.

Python coding style

It is quite common for beginner to skip the coding style and conventions in any programming language. But when you have a chance to revisit your code or others’ code, you will soon recognise how important of following coding conventions.

To learn more, you can visit PEP 8 — Style guide for Python code that includes everything you need to know, such as indentation, commenting, declaration, initialization etc. Examples:

True value testing

In Python, any object can be tested for Boolean truth value. Any object is considered to be equivalent to Boolean true, unless its class defines a Bool method that returns false, or has a len method that returns a zero-length. So, let’s look first at the built-in objects that evaluate to false

  •  False and None evaluate to false
  • Numeric zero values: 0, 0.0, 0j
  • Decimal(0), Fraction(0, x)
  • Empty set and sequence/collections: {}, []. Keep in mind that if you are familiar with JavaScript, JS will return True when you evaluate empty sets.

In custom objects, they are by default considered to be true, unless they override the boolfunction and return a false value, or they override the len function and return a value of zero.

Strings and bytes

In Python 3, there are very important differences between the notions of strings and bytes. A string in Python 3 is a sequence of Unicode characters, while bytes are a sequence of raw eight-bit values.

 If you want to combine a string with bytes, you have to decode the bytes into a string. And I can do that using the built-in decode function. Likewise, you can use encode to convert a string to bytes.

Thanks for reading. I will see you in the next post.

Add comment

A.I, Data and Software Engineering

PetaMinds focuses on developing the coolest topics in data science, A.I, and programming, and make them so digestible for everyone to learn and create amazing applications in a short time.

Pin It on Pinterest


You have successfully subscribed to the newsletter

There was an error while trying to send your request. Please try again.

Petaminds will use the information you provide on this form to be in touch with you and to provide updates.