print('Hello, World!')
Python Basics
Introduction to Python
What is Python?
Python is a high-level, interpreted programming language. This is a simple Python code:
Variables and Data Types
In Python, variables can store data of different types without explicitly declaring the type.
For example:
= 10
integer_variable = 'Hello'
string_variable = 10.5
float_variable
float_variable
10.5
Control Structures
Python supports the usual logical conditions from mathematics:
# Equals: a == b
# Not Equals: a != b
# Less than: a < b
# Less than or equal to: a <= b
# Greater than: a > b
# Greater than or equal to: a >= b
These conditions can be used in several ways, most commonly in ‘if statements’ and loops.
# if statement:
if 5 > 2:
print('Five is greater than two!')
Functions
A function is a block of code which only runs when it is called.
You can pass data, known as parameters, into a function.
A function can return data as a result.
# Defining a function:
def my_function():
print('Hello from a function')
# Calling a function:
my_function()
Lists and Dictionaries
A list is a collection which is ordered and changeable.
A dictionary is a collection which is unordered, changeable and indexed.
# List example:
= ['apple', 'banana', 'cherry']
my_list
# Dictionary example:
= {'name': 'John', 'age': 36} my_dict