Developed by Guido Van Rossum in 1991, Python is a general-purpose language for creating web and software applications, automating tasks, and analyzing and visualizing data.
To get started with Python, you need to learn the basics first.
- Basic Python Syntax
- Indentation Rules and Comments
- Variables and Data Types
- Type Casting
- Conditional Statements
- Loops and Iterators
Basic Python Syntax
Python syntax is specially designed for code reliability. It eliminates the use of semicolons after the end of a statement and curly braces to delimit the code blocks. Instead, it leverages indentation, i.e., spaces, to define the scope of functions, loops, and classes.
Indentation Rules and Comments
Indentation implies spaces at the beginning of a code statement. It is advisable to use whitespaces rather than tabs. Also, it indicates a block of code.
Python comments make code more readable and begin with ‘#’. There is no syntax for multi-line comments.
Variables and Data Types
A Variable is any name assigned to a memory location or a container to store a data value. There is no command in Python to declare a variable.
A data type in Python represents the type of value you assign to a variable. There is no need to define the data type of a variable.
Type casting is a process of converting the data type of variable into another desired data type. Python supports implicit and explicit type casting.
While implicit type casting takes place automatically, explicit type casting requires user involvement.
Operators in Python are used to perform operations on variables. Python supports Arithmetic operators, assignment operators, comparison operators, logical operators, identity operators, membership operators, and bitwise operators.
Conditional statements or decision-making statements in Python are used to execute a specific block of code if the specified condition evaluates to true. Python comes with if, if-else, elif, nest if-else, and switch-case conditional statements.
Loops and Iterators
Python loops are used to execute a particular block of code a given number of times. Three types of loops supported by Python are for loop, while loop, and do-while loop.
A Python iterator is an object that navigates through all the values within the iterable objects, such as lists, dictionaries, tuples, and sets.