Uploaded by Nevan Bhagat

Python for Beginners: A Simple Guide

advertisement
Python for Absolute Beginners
Chapter 1: What is Python?
Python is a high-level, interpreted programming language known for its simplicity and readability. It is widely
used for web development, data analysis, automation, artificial intelligence, and more.
Chapter 2: Installing Python
Download Python from python.org and follow the instructions for your operating system. Make sure to check
the box 'Add Python to PATH' during installation.
Chapter 3: Your First Python Program
Open an editor or IDE, type:
print('Hello, world!')
and run it. This prints a message to the screen.
Chapter 4: Variables
Variables store information. Example:
name = 'Alice'
age = 25
Chapter 5: Numbers and Math
You can do basic math:
x=5+3 #8
x = 10 - 4 # 6
x = 6 * 7 # 42
x = 8 / 2 # 4.0
Python for Absolute Beginners
Chapter 6: Strings
Strings are text enclosed in quotes:
greeting = 'Hello'
name = "Alice"
full = greeting + ' ' + name
Chapter 7: Getting User Input
You can ask the user for input:
name = input('What is your name? ')
print('Hello, ' + name)
Chapter 8: If Statements
Use if/else to make decisions:
age = 18
if age >= 18:
print('Adult')
else:
print('Minor')
Chapter 9: Loops
For loop:
for i in range(5):
print(i)
While loop:
i=0
while i < 5:
Python for Absolute Beginners
print(i)
i += 1
Chapter 10: Functions
Functions group code:
def greet(name):
print('Hello, ' + name)
greet('Alice')
Practice Exercises
1. Write a program that prints your name.
2. Ask for the user's age and print if they are an adult.
3. Write a function that takes two numbers and returns their sum.
4. Loop through numbers 1 to 10 and print only even numbers.
Download