0% found this document useful (0 votes)
4 views3 pages

Python Basics Guide

The document provides an overview of Python programming basics, covering topics such as variables, data types, operators, control flow, loops, functions, data structures, string operations, input/output, file handling, exception handling, modules, classes, and built-in functions. Each section includes brief explanations and examples to illustrate key concepts. It serves as a foundational guide for beginners learning Python.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

Python Basics Guide

The document provides an overview of Python programming basics, covering topics such as variables, data types, operators, control flow, loops, functions, data structures, string operations, input/output, file handling, exception handling, modules, classes, and built-in functions. Each section includes brief explanations and examples to illustrate key concepts. It serves as a foundational guide for beginners learning Python.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Python Basics

1. Introduction to Python:

- Python is a high-level, interpreted programming language.

- Syntax is clean and easy to read.

2. Variables and Data Types:

- Variable assignment: x = 5

- Data types: int, float, str, bool, list, tuple, dict, set

3. Operators:

- Arithmetic: +, -, *, /, %, **

- Comparison: ==, !=, >, <, >=, <=

- Logical: and, or, not

4. Control Flow:

- if, elif, else statements

- Example:

if x > 0:

print("Positive")

5. Loops:

- for loops: for i in range(5): print(i)

- while loops: while x < 10: x += 1

6. Functions:
- def greet(name):

return "Hello " + name

7. Data Structures:

- List: [1, 2, 3]

- Tuple: (1, 2, 3)

- Dictionary: {"key": "value"}

- Set: {1, 2, 3}

8. String Operations:

- Concatenation: "Hello" + "World"

- Methods: .upper(), .lower(), .strip(), .split()

9. Input and Output:

- input(): name = input("Enter your name: ")

- print(): print("Hello", name)

10. File Handling:

- Reading: open('file.txt', 'r')

- Writing: open('file.txt', 'w')

11. Exception Handling:

- try:

# code

except Exception as e:

print(e)
12. Modules and Packages:

- import math

- from datetime import datetime

13. Classes and Objects:

- class Person:

def __init__(self, name):

self.name = name

def greet(self):

print("Hello", self.name)

14. Useful Built-in Functions:

- len(), type(), range(), enumerate(), zip(), map(), filter(), lambda

15. Comments:

- Single-line: # This is a comment

- Multi-line: '''This is a multi-line comment'''

You might also like