Python is a high-level, interpreted, scripting, imperative, object-oriented, functional, dynamically typed, strong programming language. It was released by Guido van Rossum in 1991. The Python language has a clear and readable syntax that makes it easy for beginners to learn programming.
Indentation
Python uses indentation to delimit blocks of code. Unlike other languages that use specific keys or keywords for this. Indentation in Python isn't just for aesthetics, it's a functional part of the language. See example:
if 5 > 2: print("Five is greater than two!")
If you don't indent correctly, Python will throw an error.
Comments
Python comments begin with the hash character, #, and extend to the end of the physical line. A comment can appear at the beginning of a line or after white space or code, but not within a string literal. A hash character inside a string literal is just a hash character. See example:
# This is a comment print("Hello World!")
Variables
In Python, variables are created when you assign them a value:
x = 5 y = "Hello World!"
Python is dynamically typed, which means you can change the type of a variable in your code:
x = 4 # x is of type int x = "Sally" # x is now of type str
Data Types
Python has the following data types built in by default, in these categories:
- Text Type: str
- Numeric Types: int, float, complex
- Sequence Types: list, tuple, range
- Mapping Type: dict
- Set Types: set, frozenset
- Boolean Type: bool
- Binary Types: bytes, bytearray, memoryview
Strings
Python strings are enclosed in either single quotes or double quotes.
print("Hello") print('Hello')
Multi-line strings:
a = """Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incident ut labore et dolore magna aliqua.""" print(a)
Operators
Python divides operators into several types:
- Arithmetic Operators
- Assignment Operators
- Comparison Operators
- Logical operators
- Identity Operators
- Association Operators
- Bitwise Operators
In short, the basic syntax of Python is very easy to learn and use, especially for newcomers to programming. With its use of indentation and its clear structure, you can write readable and easy-to-understand Python code.