Introduction to Python
Python is a beginner-friendly programming language that is easy to read and write. It is widely used in web development, data science, automation, and artificial intelligence.
1. Printing Messages
The print()
function is used to display messages on the screen.
print("Hello, world!")
2. Variables and Data Types
Variables store information that can be used later.
name = "Alice" # String
age = 13 # Integer
height = 1.6 # Float
is_student = True # Boolean
3. User Input
The input()
function allows users to enter information.
name = input("What is your name? ")
print("Hello, " + name + "!")
4. Basic Operations
Python can perform mathematical operations like addition, subtraction, multiplication, and division.
x = 10
y = 3
print(x + y) # Addition
print(x - y) # Subtraction
print(x * y) # Multiplication
print(x / y) # Division
print(x % y) # Modulus (remainder)
5. Conditional Statements
The if
statement allows you to make decisions in your code.
age = 13
if age >= 18:
print("You are an adult.")
else:
print("You are a minor.")
6. Loops
Loops help repeat a block of code multiple times.
a) for
loop
for i in range(5):
print("Iteration", i)
b) while
loop
count = 0
while count < 5:
print("Count is", count)
count += 1
7. Functions
Functions allow us to reuse code by defining reusable blocks.
def greet(name):
print("Hello, " + name + "!")
greet("Alice")
greet("Bob")
These are the basic concepts of Python. As you progress, you will learn about more advanced topics like lists, dictionaries, and object-oriented programming!