Python Learning

Python is an easy to learn, powerful programming language. It has efficient high-level data structures and a simple but effective approach to object-oriented programming. Python’s elegant syntax and dynamic typing, together with its interpreted nature, make it an ideal language for scripting and rapid application development in many areas on most platforms.

Naming Styles

The table below outlines some of the common naming styles in Python code and when you should use them:

TypeNaming ConventionExamples
FunctionUse a lowercase word or words. Separate words by underscores to improve readability.function, my_function
VariableUse a lowercase single letter, word, or words. Separate words with underscores to improve readability.x, var, my_variable
ClassStart each word with a capital letter. Do not separate words with underscores. This style is called camel case or pascal case.Model, MyClass
MethodUse a lowercase word or words. Separate words with underscores to improve readability.class_method, method
ConstantUse an uppercase single letter, word, or words. Separate words with underscores to improve readability.CONSTANT, MY_CONSTANT, MY_LONG_CONSTANT
ModuleUse a short, lowercase word or words. Separate words with underscores to improve readability.module.py, my_module.py
PackageUse a short, lowercase word or words. Do not separate words with underscores.package, mypackage
How to Write Beautiful Python Code With PEP 8 – Real Python
Learn how to write high-quality, readable code by using the Python style guidelines laid out in PEP 8. Following these guidelines helps you make a great impression when sharing your work with potential employers and collaborators.

print(2 ** 3 ** 2) = 512

Explanation:

Remember, we have not used brackets here. And Exponent operator ** has right-to-left associativity in Python.

x = y += 2 (Syntax Error): expression is Invalid