*Introduction to Python Basics*
What is Python?
Python is a high-level, interpreted programming language that is widely used for various purposes such as web development, scientific computing, data analysis, artificial intelligence, and more.
Features of Python
1. *Easy to learn*: Python has a simple syntax and is relatively easy to learn, making it a great language for beginners.
2. *High-level language*: Python is a high-level language, meaning it abstracts away many low-level details, allowing you to focus on the logic of your program.
3. *Interpreted language*: Python code is interpreted line by line, making it easier to write and test code.
4. *Object-oriented*: Python is an object-oriented language, which means it organizes code into objects that contain data and functions that operate on that data.
Basic Syntax
1. *Indentation*: Python uses indentation to denote block-level structure.
2. *Variables*: Variables are used to store values, and can be assigned using the assignment operator (=).
3. *Data types*: Python has several built-in data types, including integers, floats, strings, lists, and dictionaries.
4. *Control structures*: Python has several control structures, including if-else statements, for loops, and while loops.
Basic Data Types
1. *Integers*: Whole numbers, e.g. 1, 2, 3, etc.
2. *Floats*: Decimal numbers, e.g. 3.14, -0.5, etc.
3. *Strings*: Sequences of characters, e.g. "hello", 'hello', etc. Strings can be enclosed in single quotes or double quotes.
4. *Lists*: Ordered collections of items, e.g. [1, 2, 3], ["a", "b", "c"], etc.
5. *Dictionaries*: Unordered collections of key-value pairs, e.g. {"name": "John", "age": 30}, etc.
Basic Operators
1. *Arithmetic operators*: +, -, *, /, %, etc.
2. *Comparison operators*: ==, !=, <, >, <=, >=, etc.
3. *Logical operators*: and, or, not, etc.
4. *Assignment operators*: =, +=, -=, *=, /=, etc.
Basic Control Structures
1. *If-else statements*: Used to execute different blocks of code based on conditions.
2. *For loops*: Used to iterate over sequences, such as lists or strings.
3. *While loops*: Used to execute a block of code repeatedly while a condition is true.
Example Code
```
Print "Hello, World!" to the screen
print("Hello, World!")
Ask the user for their name
name = input("What is your name? ")
Print a greeting message
print("Hello, " + name + "!")
Ask the user for their age
age = int(input("How old are you? "))
Print a message based on the user's age
if age < 18:
print("You are a minor.")
elif age >= 18 and age < 65:
print("You are an adult.")
else:
print("You are a senior citizen.")
```
This is just a brief introduction to the basics of Python. With practice and experience, you can become proficient in using Python for a wide range of applications.
- Teacher: Admin User