Overview
Nowadays Python is one of the very popular language. Python is developed by Guido van Rossum, and released in 1991.
Python is a high-level, interpreted and object-oriented scripting language.
Python 3 is an enhanced version of Python 2 programming language which released in 2008.
In case of Python code compilation not required as it execute directly at runtime.
Python is easy to learn and work, It is portable, scalable and extendable. Python provides multiple libraries to connect with database and process large amount of data.
Python 3 code is not completely backward compatible with Python 2 code. Due to this, everyone got stuck using Python 2. Early Python 3 was slower. They improved the features and made it faster for the future.
Java and JavaScript shows lots of similarities with Python.
Python can be used as:
- Server side programming
- Software development
- scripting language
Python majorly supported by most of the operating systems.
Python Indentation:
Python doesn’t depend on semicolons to execute a statement. It considers a single line a statement as executed. For Python, changing a line is a new statement.
Python completely works on indentation, use whitespace to define scope.
It is recommended to use 4 spaces in place of giving a tab to maintain indentation and avoid compile time errors.
If code is not properly indented, it will give us the below error:
OUTPUT:
If code indentation is properly done, it will not cause any issues.
OUTPUT:
hello
Comments
Comments make code more human readable and help others also to understand it better.
Proper use of comment let developer know the code functionality. Comments always ignore by the compiler or interpreter while compiling or interpreting the code.
Comment can also be given to code to not to run or execute.
In Python, comment can be provided by using # character symbol.
It can be given anywhere either on top or right side of the line.
Below is the comment example highlighted as black:
OUTPUT:
hello
Python Quotes:
Python provides three type of quotes as single( ‘ ), double ( “ ) and three triple(‘ ’ ’, “ ” ” ) quotes.
Single and double quote use for single line string assignment.
triple quote use for multiple line string assignment such as multiline paragraph.
Example
OUTPUT:
Variable Naming Convention
- Variable name must be start with alphabet letter or underscore(_).
- Variable name can not start with numeric digit.
- Only underscore is allowed, no other special characters are allowed (!, #, $, %, ^, &, *).
- Variable name can not be on keyword’s name supported by Python.
5. Variable names are case sensitive. for example, mycar, myCar and my_car are totally different variables.
Valid variables
my_ca, _my_car, myCar, my_car_1
Invalid variables
1_my_ca, 1macar, my%car, my#car
Python variable name can be camel case, pascal and snake case.
Camel Case: First letter will always be small letter and next letter of starting word will always be capital. e.g. carName, carEngineType
Pascal Case: It is like camel case with one difference where first letter will always be capital. e.g. CarName, CarEngineType
Snake Case: all letters will be small and words separated by underscore(_). e.g. car_name, car_engine_type.
Imran Khan, Adobe Community Advisor, AEM certified developer and Java Geek, is an experienced AEM developer with over 11 years of expertise in designing and implementing robust web applications. He leverages Adobe Experience Manager, Analytics, and Target to create dynamic digital experiences. Imran possesses extensive expertise in J2EE, Sightly, Struts 2.0, Spring, Hibernate, JPA, React, HTML, jQuery, and JavaScript.