
Let us dive into the world of Python programming with Python basics. You can either start learning Python with a reputed online learning program providing you with career guidance and more. However, we are going to discuss some Python basics to help you get started with the Python programming language this year.
Some of the key characteristics of Python Programming language are listed below.
Python supports all data types and variables within its framework. Being a dynamically typed language you do not explicitly need to declare Python data type as it can recognize the data type and store it accordingly.
Data types are kinds of data items stored in a variable while variables are containers used to store data. Let us know some of the frequently used data types in Python basics.
| Category | Data Type |
| Primitive Data Types | int |
| float | |
| complex | |
| bool | |
| str | |
| Secondary Data Types | list |
| tuple | |
| set | |
| dict | |
| frozenset | |
| byte, byte array |
Check a clear explanation of Python basics rules for naming variables without causing syntax errors.
Let us learn what indentation is in Python and its importance for writing Python programs. Indentation in Python is used to create a whitespace using a space keypad or tab which can be used at the beginning of a line to define blocks of code. Python relies on indentation to determine the structure of code rather than using brackets.
| # Correct indentation def greet(): print("Hello, world!") # Indented block inside function greet() |
| def say_hello(): print("Hello!") # Missing indentation (Expected IndentationError) |
| IndentationError: expected an indented block |
| print("Hello, World!") |
| x = 5 + 3 # Expression: 5 + 3 is evaluated and assigned to x print(x) # Output: 8 |
| age = 18 if age < 18: print("Minor") else: print("Adult") # Output: Adult |
| for i in range(3): print(i) # Output: 0, 1, 2 |
| for i in range(5): if i == 3: break # Stops loop when i = 3 print(i) # Output: 0, 1, 2 |